因此,無論出于何種原因,這段代碼都沒有響應。我有一個敵人,我一直試圖讓它面對玩家(敵人周期性地來回掠過玩家的頭)。但是,除了在計時器達到 0 時發(fā)生翻轉(zhuǎn)(這并不能很好地工作)之外,我無法讓 Flip 功能正常工作。我知道 Flipper 功能很好;我已經(jīng)測試了它和一切。我只是不知道如何告訴敵人,當玩家在它的左邊時,要轉(zhuǎn)彎,反之亦然。using System.Collections;using System.Collections.Generic;using UnityEngine;public class dragoonDetection : MonoBehaviour {private Rigidbody2D rb;private Animator anim;public Transform Player;private bool facingRight = true;void Start (){ rb = GetComponent<Rigidbody2D> (); anim = GetComponent<Animator> ();}void Update(){ Flip();} void Flip(){ if (Player.transform.localScale.x > 0) { transform.localScale = new Vector3 (1.69f, 1.54f, 1f); } if (Player.transform.localScale.x < 0) { transform.localScale = new Vector3 (-1.69f, 1.54f, 1f); }}void Flipper(){ facingRight = !facingRight; Vector2 theScale = transform.localScale; theScale.x *= -1; transform.localScale = theScale;}}有什么想法嗎?我寧愿避免使用 FindGameObject,因為它實際上并不是在尋找玩家腳本。它正在尋找一個沒有附加到播放器的腳本的子變換。而且因為我有兩個不同的玩家游戲?qū)ο?,您可以在游戲中隨時切換它們,所以在這方面對我來說真的不起作用。
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報
0/150
提交
取消