GetComponent() returning an error

I’m adding a small script to a mesh that has a CharacterController component that will move the mesh. I want to use the ChraracterControllers Move method. So I try to obtain the CharacterController of the gameObject that the script is attached to.

using UnityEngine;
using System.Collections;

[RequireComponent (typeof (CharacterController))]

public class Move_Ship : MonoBehaviour {
	
	private Vector3 moveDirection;
	CharacterController controller;
	
	// Use this for initialization
	void Start () {
		controller = GetComponent(CharacterController); // This gives me an error
		moveDirection.z = 0.0f;
	}

        .....
}

The error I get is

In C# you have to use GetComponent(typeof(CharacterController)) - similar to how you did it in RequireComponent attribute.

Ahh, thanks a lot :slight_smile: