Hi, I’m extremely new to Unity and any form of coding especially C#. I have encountered a problem whilst following a tutorial on a “FirstPersonController” script. I’ll include the code below but to summarise, I keep getting the error “Non-invocable member ‘PlayerController.moveDirection’ cannot be used like a method”.
How can I resolve this issue as I just want to create a controller so I can continue creating my game?
Thanks for any help in advance!
using UnityEngine;
public class PlayerController : MonoBehaviour
{
//Public Variables
public float walkspeed;
//Private Variables
Rigidbody rb;
Vector3 moveDirection;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
//Non-Physics steps
//Get directional input from the user
float horizontalMovement = Input.GetAxisRaw("Horizontal");
float verticalMovement = Input.GetAxisRaw("Vertical");
moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
}
void FixedUpdate()
{
//Physics steps
//Call the Move function
moveDirection();
}
void Move()
{
//Here we define the move funtion
//Rigid.velocity is a method which takes a Vector3 and controls the speed and direction of the GameObject
rb.velocity = moveDirection * walkspeed * Time.deltaTime;
}
}
UPDATE
The script is almost identical however, I’m recieving even more issues???
using UnityEngine;
public class PlayerController : MonoBehaviour
{
//Public Variables
public float walkspeed;
//Private Variables
Rigidbody rb;
Vector3 moveDirection;
void Awake()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
//Non-Physics steps
//Get directional input from the user
float horizontalMovement = Input.GetAxisRaw("Horizontal");
float verticalMovement = Input.GetAxisRaw("Vertical");
moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
}
void FixedUpdate()
{
//Physics steps
//Call the Move function
Move();
}
void Move()
{
//Here we define the move funtion
//Rigid.velocity is a method which takes a Vector3 and controls the speed and direction of the GameObject
rb.velocity = moveDirection * walkspeed * Time.deltaTime;
}
}
The issues are as follows:
-
Assets\Scripts\PlayerController.cs(3,14): error CS0101: The namespace ‘’ already contains a definition for ‘PlayerController’
-
Assets\Scripts\PlayerController.cs(14,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Awake’ with the same parameter types
-
Assets\Scripts\PlayerController.cs(19,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Update’ with the same parameter types
-
Assets\Scripts\PlayerController.cs(30,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘FixedUpdate’ with the same parameter types
-
Assets\Scripts\PlayerController.cs(39,10): error CS0111: Type ‘PlayerController’ already defines a member called ‘Move’ with the same parameter types
Can somone explain what these mean as I have no idea how to fix it?
Many Thanks