Access component from another script

前端 未结 2 546
渐次进展
渐次进展 2021-01-29 11:37

Im using unity and I have Im trying to access a script called Outline on my parent object. I need to disable and enable the script Outline from another

2条回答
  •  旧时难觅i
    2021-01-29 12:12

    If its on your parent object then:

    myScript = gameObject.transform.parent.gameObject.GetComponent();
    

    Other good Solution(cos performance is not critical here) by Hugo:

    myScript = gameObject.GetComponentInParent;
    

    Not in unity enviroment but i think in the second case gameObject is redundant.

提交回复
热议问题