- Home /
Can Only Reference My Own Scripts
Hello. I'm trying to disable a script from another. For some reason, I can only use GetComponent
with my own Scripts I have written. For example, say I have "MyScript", attached to my player object. I could do the following in order to disable it.
MyScript mS = GetComponent<MyScript>();
mS.enabled = false;
This would work and the game would run as normal. But, if I try and use any of the standard assets, e.g. Character Motor, Unity will give me something along these lines:
The name 'Standard Asset Script' does not exist in the current context.
I do not understand this. If I can reference anything in my Assets, then why can't I access these scripts?
Answer by tanoshimi · Jun 17, 2014 at 07:03 PM
You didn't include the code that fails (which would have been more useful than the code that you know works), but from the error message it looks like you were trying to write:
GetComponent("Standard Asset Script");
Instead, you need to specify the type of component, e.g.:
GetComponent("CharacterController");
(or, most people prefer the generic version):
GetComponent<CharacterController>();
Your answer
Follow this Question
Related Questions
Disable a GameObjects scripts knowing only the GameObjects name 3 Answers
Disable SCRIPT HELP!!!! 1 Answer
What am I doing wrong when disabling a script? 1 Answer
Can't modify variable from another gameobject script 0 Answers
How can assign just 1 specific prefab to 1 specific player?(Multiplayer) 0 Answers