Script can't be disabled from another script.

Hi there everyone! So, I’m currently making a weapon for my game, and when I shoot it and it hits the target, it should disable his patroling script, but it totally doesn’t.Any other thing works fine, like let’s say the animations or the navmeshagent work as intended and get changed/disabledd.

I have tried different techniques like the following :

// tried this

GetComponent<FOVDetection>().enabled = false;

// tried getting the game object before accesing this
public GameObject killer;

Killer.GetComponent<FOVDetection>().enabled = false;

// also tried declaring a monobehaviour and disable that

public MonoBehaviour script;

void Start() {

script = GetComponent<FOVDetection>();

}

// and then trying to do this

script.enabled = false;

// Tried searching the gameObject and disable it like that

GameObject.Find("Killer").GetComponent<FOVDetection>().enabled = false;

// Also tried like this

     FOVDetection fovdetection = GetComponent<FOVDetection>();

// and then disabling it like this

     fovdetection.enabled = false;

Let’s just say I tried a bunch of ways.I also tried deleting the awake method in the FOVDetection script and keeping all of that together with the other stuff that was in start, that also didn’t work.I’ve ran out of ideas and I needed to finish this so I could push my app update before the deadline that I’ve set for myself.

Does anybody have any sort of idea why this is happening and how I could fix it?I’m desperate at this point as I can’t understand what is going wrong in here.

Thank you so much for the help!

Don’t disable the script, just run the whole routine through an ‘isActive’ bool and switch it off that way. :wink:
Simple as hell, and works perfectly.

1 Like

I will try and do that tomorrow and come back with an update, thanks for the suggestion!

I’ve found the issue, I have recently changed the script with another one, and forgot that I was using that instead of FOVDetection , so basically I was disabling a script that wasn’t used haha.My mistake, thanks for the help!