I am brand new at this, and I am having a few conundrums about this code that I put in. I followed a tutorial and I am still having some issues. All I want to do is move the object that I have this script attached to called Player, and the script is PlayerMovement.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public object Player(PlayerMovement) { // Identifier expected, and 'PlayerMovement.Player(PlayerMovement)' not all codes return a value
{
if (Input.GetKeyDown(KeyCode.W))
{
Transform.Translate(Vector3.forward * Time.deltaTime); //ERROR: An object reference is required for the non-static field, method or property 'Transform.Translate(vector3)
Debug.Log("W is pressed, and I should move forwards.");
}
if (Input.GetKeyDown(KeyCode.S))
{
Debug.Log("S is pressed, and I should move backwards.");
}
if (Input.GetKeyDown(KeyCode.A))
{
Debug.Log("A is pressed, and I should move left.");
}
if (Input.GetKeyDown(KeyCode.D))
{
Debug.Log("D is pressed, and I should move right.");
}
}
}
On line 22 I am getting 2 errors Identefier expected, and 'PlayerMovement.Player(PlayerMovement)' not all codes return a value.
On line 29 I am getting An object reference is required for the non-static field, method or property 'Transform.Translate(vector3)'
As I am brand new, I have been looking up answers for hours upon hours and every answer I come across whenever I google anything doesn't actually explain what I am doing wrong, or I just am not reading it properly.