[英]In Unity and NGUI, a prefab, onClick notify works on public function but the boolean loses it's value in update
I am trying to add an NGUI button, that rotates instances of a game object using a controller script that works fine when pressing the arrow keys. 我试图添加一个NGUI按钮,该按钮使用控制器脚本旋转游戏对象的实例,该控制器脚本在按箭头键时效果很好。 I started using NGUI to add buttons. 我开始使用NGUI添加按钮。 The buttons have a notify on Click that selects a function from the game object's controller script. 这些按钮具有单击通知,可以从游戏对象的控制器脚本中选择一个功能。
I added a rotate function that changes a boolean for the script, the boolean changes when the button is clicked, but when the value is accessed from the update function it's value is not correct. 我添加了一个rotate函数,该函数会更改脚本的布尔值,单击按钮时布尔值会更改,但是当从update函数访问该值时,该值不正确。
I assumed it had something to do with the instances of the gameobject, or I am not retrieving the game object in question. 我认为这与游戏对象的实例有关,或者我没有检索有问题的游戏对象。 So I tried both of those and the Boolean still doesn't update correctly. 因此,我尝试了这两种方法,但布尔值仍然无法正确更新。
Here is the code for my controller: 这是我的控制器的代码:
private bool rotate;
// This is the function in the notify part of onClick in the NGUI button.
public void rotateHero () {
rotate = true; // This works it sets it to true.
}
public void Update()
{
UpdateInput();
//if (_nextFallStep.PopIsOccurred() && Time.time - _lastInputTime >= InputDelay)
if (_nextFallStep.PopIsOccurred())
{
MoveDown();
_lastInputTime = Time.time;
}
}
private void UpdateInput()
{
if (rotate) {
if (Board.CanRotate(_block))
_block.Rotate();
debug.log(rotate); //Always returns false.. when it should be true.
rotate = false;
}
私有变量必须是静态的。
static bool rotate;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.