我在场景中的随机位置为objectCreation编写了一个方法。当玩家挥动屏幕时,我希望在我的游戏中发生这种情况。我使用以下代码
void Start(){
StartCoroutine (SwipeInput ());
}
void Update(){
if (Swiped) {
if (Direction == Vector2.up) {
RandomObjects ();
} else if (Direction == Vector2.right) {
RandomObjects ();
} else if (Direction == -1 * Vector2.up) {
RandomObjects ();
} else if (Direction == -1 * Vector2.right) {
RandomObjects ();
}
}
}
IEnumerator SwipeInput ()
{
while(true){
if (Input.touchCount > 0) {
Touch t = Input.GetTouch (0);
Swiped = false;
Vector2 initial = t.position;
yield return new WaitForSeconds (0.5f);
Direction = (t.position - initial).normalised;
Swiped = true;
yield return new WaitForSeconds (0.5f);
} else {
Swiped = false;
}
}
}
但在Coroutine中,游戏并不适用(真实)。感谢。
答案 0 :(得分:-1)
你应该写“normaliZed”而不是“normalized”