###前提・実現したいこと
オブジェクトが移動して数秒後、移動前の位置にまた戻り再び移動させたい
###発生している問題・エラーメッセージ
移動して元に戻るには戻るのですが戻ると移動の処理が働かなくなります
###該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; public class RrocketPunchi : MonoBehaviour { public bool Moveflg; public GameObject Rrocket; private float timer; private Vector3 startPosition; // Use this for initialization void Start() { Moveflg = false; timer = 0.0f; startPosition = transform.position; } // Update is called once per frame void Update() { timer += Time.deltaTime; if (Input.GetKey(KeyCode.M) && Input.GetKey(KeyCode.P)) { Moveflg = true; } if (Moveflg) { Rrocket.transform.rotation = this.gameObject.transform.rotation; transform.position += transform.forward * 30f * Time.deltaTime; } if(timer >=7.0f) { transform.position = startPosition; } } }
###試したこと
7秒後に戻す処理を成功したのはいいものの、戻ってから動かなくなってしまった。おそらく一番下のif分が原因だと思うけど、どのようにすれば動くのか教えていただきたいです。
###補足情報(言語/FW/ツール等のバージョンなど)
C# unity
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。