Hello everyone!
Beginner here. I’m trying to follow a tutorial, and I’m programming in C#. Unfortunately, the tutorial happens to be in Java. The error comes from when I’m trying to pull a CharacterController associated with the Player object. Here is the relevant code:
public CharacterController control;
public Vector3 friction; //friction on the player
// Use this for initialization
void Start () {
control = gameObject.GetComponent (CharacterController) as CharacterController;
}
The same error happens on this friction segment:
void calculatePhysics (float xFriction, float yFriction)
{
friction = Vector3 (-xFriction * velocity.x, -yFriction * velocity.y, 0);
}
I’m also getting the following errors on the first example:
Assets/Scripts/Physics.cs(24,38): error CS1503: Argument #1' cannot convert object’ expression to type System.Type' Assets/Scripts/Physics.cs(24,38): error CS1502: The best overloaded method match for UnityEngine.GameObject.GetComponent(System.Type)’ has some invalid arguments
Thoughs? Thanks everyone!
control = gameObject.GetComponent (typeof(CharacterController)) as CharacterController;
or
control = gameObject.GetComponent (“CharacterController”) as CharacterController;
or
control = gameObject.GetComponent ();
REF: Unity - Scripting API: GameObject.GetComponent