Question by
Khudere · Apr 04, 2017 at 02:58 PM ·
gameobject
C# - using getcompenent
Hello,
I have been trying to search for this, but i cannot seem to find it anywhere. Is it possible to active and disable a script on a GameObject from another GameObject?
Object A: Contains ScriptA
Object B: Contains ScriptB that deactivates script A when loaded.
I was thinking something like (from ScriptB):
public GameObject GameObjectA;
Void Start () {
GameObjectA.GetComponent(ScriptA).enabled = false;
}
Comment
Best Answer
Answer by AndreM1 · Apr 04, 2017 at 03:09 PM
Similar, use this:
public GameObject GameObjectA;
private void Start(){
GameObjectA.GetComponent<ScriptA>().enabled = false;
}
Or consider doing this:
public ScriptA script;
private void Start(){
script.enabled = false;
}
Your answer
Follow this Question
Related Questions
Creating depth for background objects 0 Answers
Position Array Returning null reference 1 Answer
interact objects images or canvas 1 Answer