Get Component Errors

In my scripts I’m trying to locate two other components and disable them from an inventory system.

My Script:

private var showGUI : boolean = false;

function Update()
{
	if (Input.GetKeyDown ("i"))
	{
		showGUI = !showGUI;
	}
	
	if (showGUI == true)
	{
		Time.timeScale = 0;
		GameObject.Find("Player").GetComponent(ClickToMove).enabled = false;
		GameObject.Find("PlayerCam").GetComponent(UserCamera).enabled = false;
	}
}

The script detects the Gameobjects: “Player”, and “PlayerCam”, but it does not detect the component scripts: “ClickToMove”, and “UserCamera”, even though I’ve checked, double checked, renamed, and triple checked, that the files were there, and that the names matched it doesn’t detect either of the two scripts.

Any help is greatly appreciated.

GetComponent takes in the type of your script, which in C# you can do like this:

GetComponent(typeof(ClickToMove));
GetComponent<ClickToMove>( );

The second and easier version is called a generic function.

Also, you can avoid typing mistakes by using function overloads with constant values like this:

Input.GetKeyDown(KeyCode.A)