0
ゲームの「トリガー」ゾーンを終了するときにオブジェクトをドロップしようとしています。オブジェクトが浮動を開始するトリガーゾーンに入るとどうなりますか?しかし、私がゾーンを離れるとき、オブジェクトは地面に落ちない。私はトリガーゾーンに再び入ると空中で停止し、再びフロートする。ここでトリガーゾーンを離れるときにオブジェクトを落とす方法は?
は、フローティングのための私のスクリプトです:
using UnityEngine;
using System.Collections;
public class Floatinga : MonoBehaviour {
public float horizontalSpeed;
public float verticalSpeed;
public float amplitude;
private Vector3 tempPosition;
void Start()
{
tempPosition = transform.position;
}
void FixedUpdate()
{
tempPosition.x += horizontalSpeed;
tempPosition.y += verticalSpeed;
transform.position = tempPosition;
}
}
そして私が出入り:
using UnityEngine;
using System.Collections;
public class Floating : MonoBehaviour {
public GameObject otherObject;
// Use this for initialization
void Start() {
otherObject.GetComponent<Floatinga>().enabled = false;
}
void OnTriggerEnter()
{
otherObject.GetComponent<Floatinga>().enabled = true;
}
// Update is called once per frame
void OnTriggerExit()
{
otherObject.GetComponent<Floatinga>().enabled = false;
}
}
だから私は私が間違っているのかわからないのですか?誰でも助けてくれますか? ありがとう
いいえ、動作しません。オブジェクトはトリガーゾーンに入ることなくただ浮動を開始し、今見られたすべてのところでバウンスしているようです。 – Newbie
FixedUpdateはオブジェクトの位置を設定していると同時に重力が作用しているためです。オブジェクトを浮動させ、重力を有効にしたい場合は重力を無効にし、浮動スクリプトを無効にする場合は無効にする必要があります。 – Everts
ああ大丈夫です。ありがとう!今働いている。 – Newbie