【问题标题】:GameObject hit doesn't return the correct value游戏对象命中没有返回正确的值
【发布时间】:2015-01-03 02:19:12
【问题描述】:

我现在没有源代码,我会尝试解释我的错误:

我创建了一个多维游戏对象数组,我为每个游戏对象创建了一个原始立方体,添加了一个脚本组件,其中包含一个具有布尔属性的类和相关的 set/get 方法,将他的属性设置为 true 并移动了变换。

然后在我的 Update() 函数中,我想获取点击的 GameObject 的属性值。

脚本正在运行,但我得到的是 FALSE 而不是 TRUE。

对于调试,我放了一个Destroy(hit.trasform.gameObject)GameObject 被销毁,但仍然记录 FALSE 而不是 true。

程序有问题吗?我忘记了什么?

如果不清楚,我稍后会在有权限时上传代码!

【问题讨论】:

  • 你使用什么方法来访问你击中的那个游戏对象
  • hit.transform.gameObject.GetComponent().getBoolean();

标签: unity3d gameobject


【解决方案1】:

Tile内创建一个函数:

public void setBoolean(bool b)
{
    yourBool = b;
    Debug.Log("Printing the boolean value: " + yourBool);
}

然后在你的碰撞代码中:

hit.transform.gameObject.SendMessage("setBoolean", true);

或者,如果您愿意:

hit.transform.gameObject.GetComponent<Tile>().setBoolean(true); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    相关资源
    最近更新 更多