###前提・実現したいこと
動かしているオブジェクトに特定のオブジェクトが諸突したら停止し、特定のオブジェクトを避けるように動かして回避したいです。
例えばこの画像のような一本道で、森のオブジェクトを下へ動かし岩のオブジェクトにぶつかったら森のオブジェクトを停止させてすり抜けないようにし、下以外の方向へ動かし岩オブジェクトを避けたいです。
###発生している問題
ぶつかったら停止させることには成功しましたが、そこからどう停止状態を解除して動かせば良いのかわかりません(ぶつかったら停止したままになります)。
###該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class test : MonoBehaviour { 6 GameObject player; //動かすオブジェクト 7 Vector2 me; 8 int flg; 9 10 // Use this for initialization 11 void Start () { 12 player = GetComponent<GameObject> (); 13 me.y = transform.position.y; 14 me.x = transform.position.x; 15 } 16 17 // Update is called once per frame 18 void Update () { 19 if (flg == 0) { 20 me.y += Input.GetAxis ("Vertical") * 1.0f * Time.deltaTime; 21 me.x += Input.GetAxis ("Horizontal") * 1.0f * Time.deltaTime; 22 } 23 transform.position = new Vector2 (me.x,me.y); 24 } 25 26 void OnCollisionEnter2D(Collision2D other){ 27 if (other.gameObject.tag == "tile") { 28 Debug.Log ("ok"); 29 flg = 1; //flgを1にして停止させる 30 } 31 } 32 33 /*void OnCollisionExit2D(Collision2D other){ 34 flg = 0; 35 }*/ 36 37} 38
情報に不足がありましたら補足致しますので、どうかお知恵をお貸しください。
宜しくお願い致します
###補足情報(言語/FW/ツール等のバージョンなど)
Unity2017.3
C#

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。