C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Walking : MonoBehaviour { 6 7 new Rigidbody2D rigidbody2D; 8 public int speed; 9 Vector3 pos; 10 int x; 11 12 void Start() 13 { 14 rigidbody2D = GetComponent<Rigidbody2D>(); 15 speed = -10; 16 } 17 18 void Update() 19 { 20 rigidbody2D.velocity = new Vector2(speed, rigidbody2D.velocity.y); 21 22 pos = transform.position; 23 24 if (pos.x == -235) 25 { 26 speed = 10; 27 Vector3 scale = transform.localScale; 28 scale.x = -1; 29 } 30 31 if (pos.x == 235) 32 { 33 speed = -10; 34 Vector3 scale = transform.localScale; 35 scale.x = 1; 36 } 37 } 38} 39
positionが-235または235になると、逆方向に進むスクリプトを書いたのですが、方向が変わってくれません。エラーなどは出ていません。なにかミスがあるでしょうか?
回答よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/08 04:35