Get Component Error

I’m having difficulty with this script. It is made to set a separate script as disabled once the main script is enabled. I’ve checked the script names, they are all correct.

using UnityEngine;
using System.Collections;

public class PowerDown : MonoBehaviour {

	public GameObject BotScript;

	// Use this for initialization
	void OnEnable () {
		BotScript.GetComponent<BotMovement>().enabled = false;
	// Update is called once per frame
	void Update () {

Please help :confused:

There is no problem with your code as long as you actually assigned the correct gameobject to the “BotScript” variable. However it would be way better to use a variable of type “BotMovement” instead of “GameObject”. That way you don’t need the GetComponent at all.

public BotMovement BotScript;
void OnEnable () {
    BotScript.enabled = false;

Of course if you change the variable type you have to re-assign your object. This is much safer as it doesn’t rely on dynamically looking up if that component exists. You directly reference your target script at edit time.