你好,我有我的問題,我需要得到更多然後1個對象與標籤玩家的transform.position所以劇本追逐多個玩家Unity GameObject.FindGameObjectsWithTag(「Player」)。transform.position;
using System.Collections.Generic;
using UnityEngine;
public class enemyChase: MonoBehaviour
{
//private GameObject[] Player;
Transform Player;
// Use this for initialization
void Start()
{
Player = GameObject.FindGameObjectsWithTag ("Player").transform.position;
}
// Update is called once per frame
void Update()
{
if (Vector3.Distance (Player.position, this.transform.transform.position) < 10) {
Vector3 direction = Player.position - this.transform.position;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation(direction), 0.1f);
if (direction.magnitude > 1) {
this.transform.Translate (0,0,0.05f);
}
}
}
}
Your'Player = GameObject.FindGameObjectsWithTag(「Player」)。transform.position;'''GameObjects'的'Array'數組。所以你應該1)用'Player = GameObject.FindGameObjectWithTag(「Player」)。transform.position;'或2)稍後在'Player'數組上循環。 – KamikyIT