如何从另一个对象激活脚本? [英] How to activate a script from another object?
本文介绍了如何从另一个对象激活脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在按下按钮时从另一个对象激活脚本.这是我尝试过的:
I'm trying to activate a script from another object on a button press. Heres what I tried:
function Update () {
if(Input.touchCount == 1) {
GameObject.Find("theobject").GetComponent(thescript).enabled = true
}
else {
GameObject.Find("theobject").GetComponent(thescript).enabled = false
}
}
当我按下播放时,没有任何错误,但是当我按下按钮时,什么也没有发生.脚本有什么问题吗?我是Unity和Java的新手.任何帮助,将不胜感激.在此先谢谢您!
When I press play, It has no errors but when I press the button, nothing happens. Are there anything wrong with the script. I'm new to Unity and Javascript. Any help would be appreciated. Thanks in advanced!
推荐答案
您可以执行以下操作:
if(GUI.Button(new Rect(10,10,100,90),"Button to activate object"))
{
gameObject.active = true;
}
这篇关于如何从另一个对象激活脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文