【发布时间】:2015-12-20 03:22:08
【问题描述】:
一个游戏对象在正方向上施加了力,然后在一段时间后在负方向上施加了力。
如果力施加在负方向,这意味着游戏结束,我想显示一个完全不同的游戏对象,它是名为 icetextureONfile 的游戏结束游戏对象。我的方法不起作用我收到错误“类型'UnityEngine.GameObject'不包含icetextureONfile的定义”。我很难参考
public void FixedUpdate() {
// No action happened yet
gameObject.icetextureONfile.SetActive (false);
// Increase the kick timer
kickTimer += Time.fixedDeltaTime;
// If the next kick time has came
if (nextKick < kickTimer) {
// Schedule the kick back corresponding to the current kick
nextKickBacks.Enqueue (nextKick + 100f);
// Apply the kick force
rb.AddForce (transform.up * thrust, ForceMode.Impulse);
// Plan the next kick
nextKick = kickTimer + Random.Range (MinKickTime, MaxKickTime);
}
// If there are more kick backs to go, and the time of the closest one has came
if (0 < nextKickBacks.Count) {
if (nextKickBacks.Peek () < kickTimer) {
// Apply the kick back force
rb.AddForce (-transform.up * thrust, ForceMode.Impulse);
// Game object was kicked down, set active game over object
gameObject.icetextureONfile.SetActive (true);
// Dequeue the used kick back time
nextKickBacks.Dequeue ();
}
}
}
【问题讨论】:
-
你在哪里定义
icetextureONfile?gameObject的类型是什么? -
在我通常只是将脚本附加到它们之前,我从来不需要定义游戏对象,因此建立了连接。我不知道有什么不同类型的游戏对象,我认为游戏对象是最小的分母?
-
您是否通过编辑器附加了对象?如果是这样,请尝试
icetextureONfile.gameObject.SetActive(true); -
没有类包含它。我现在正在尝试另一种方法,我创建了一个带有新类的新脚本,将该脚本附加到 icetextureONfile 对象,这是代码: public class GameOver : MonoBehaviour { void Start () { gameObject.SetActive (false); } // 每帧调用一次更新 void Update () { if (0
标签: c# unity3d gameobject