放置障礙物,優化玩家尋找敵方方式
This commit is contained in:
1 parent
f07d687be8
commit
c644491e93
14 files changed
+2517
-26
No files matched your search
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
// 敵人方位指示 : 箭頭轉向敵人所在的水平方向
|
||||
// 箭頭圖片朝上 = 敵人在正前方 ; 敵人在右邊時箭頭往右轉
|
||||
public class EnemyIndicator : MonoBehaviour
|
||||
{
|
||||
[Header("參照")]
|
||||
public BotSpawner spawner;
|
||||
|
||||
[Tooltip("Main Camera,以它的朝向為基準")]
|
||||
public Camera viewCamera;
|
||||
|
||||
[Tooltip("箭頭 (朝上的圖片)")]
|
||||
public RectTransform pointer;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (pointer == null) return;
|
||||
|
||||
// 機器人倒下到重生之間先隱藏
|
||||
BotHealth bot = spawner != null ? spawner.CurrentBot : null;
|
||||
bool hasTarget = bot != null && viewCamera != null;
|
||||
pointer.gameObject.SetActive(hasTarget);
|
||||
if (!hasTarget) return;
|
||||
|
||||
// 只看水平方向 : 正數 = 敵人在右邊,負數 = 在左邊
|
||||
Vector3 forward = Vector3.ProjectOnPlane(viewCamera.transform.forward, Vector3.up);
|
||||
Vector3 toBot = Vector3.ProjectOnPlane(bot.transform.position - viewCamera.transform.position, Vector3.up);
|
||||
float angle = Vector3.SignedAngle(forward, toBot, Vector3.up);
|
||||
|
||||
pointer.localEulerAngles = new Vector3(0f, 0f, -angle); // UI 的 Z 軸是逆時針,所以取負號
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user