- Home /
Turning Off Only One Instance of a Script
Hi,
I am trying to turn off a script component on one instance of an object. My issue is that when I turn off the script component that script is then turned off for all instances of that game object. I want the game object to still be visible in the world so I am using enable to turn off the component. I've been searching all day and can't seem to find an answer that is relevant to my problem.
Things I have tried:
Unpacking the prefab
Turning the off the component via the game object and the parent object
I'm still very new to game development so please forgive me if I've missed something obvious. Thank you in advance for any help!
This should not be happening. You are probably turning off the script on the prefab and not the instance. Or your script it interfering with it.
Answer by GrayLightGames · Oct 20, 2019 at 01:09 AM
Hi @tommydcooley, it might help to post your code for how you are disabling the component. Have you tried something like this:
myGameObject.GetComponent<myClass>().enabled = false;
Where myGameObject points to the instance you're talking about and myClass is the name of your class.
Your answer
Follow this Question
Related Questions
how to enable or disable a script via code c# 1 Answer
About takeover control 0 Answers
Canvas starts enabled no matter what 1 Answer
Is there a thing like a type of a script? 3 Answers
Enable/Disable Script on GameObject when pressing a key 1 Answer