ボタンを押すとGameObjectが下記のようなアクションを起こすようにしたいです。
1)GameObjectが上に上がっていく
2)ある位置まできたら2秒止まる
3)2秒後下に下がっていき最初の位置に戻る
4)2秒後 また1から始まり繰り返す
上に上がるまでは問題なくできたのですが
それ以降がうまくできません。わかる方教えてください。
環境)
PC: mac
Unity2018.3.0f2
言語:C#
using System.Collections; using System.Collections.Generic; using UnityEngine; public class HogeMooving : MonoBehaviour { #pragma warning disable 649 [SerializeField]GameObject HogeUpObject; public float timeOut; float timeElapsed; public float yPosition; Vector3 m_pos; bool moveFlag; // Start is called before the first frame update void Start() { m_pos = HogeUpObject.transform.localPosition; moveFlag = false; } // Update is called once per frame void Update() { if(moveFlag){ timeElapsed += Time.deltaTime; if(timeElapsed >= timeOut){ if(m_pos.y < yPosition){ HogeUpObject.transform.localPosition = m_pos; m_pos.y += 10.0f; } } } } public void OnClickHogeMooving(){ moveFlag = true; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/03 00:54