我有3个班级.... Station_Spawner
,Game_Manager
和Player_EnemyArrow
。
在Station_Spawner中,我有一个例程来处理产生了多少敌人以及它们之间产生的时间。
IEnumerator SpawnShips(int numofenemies, int timebetweenspawn)
{
for (int i = 0; i < numofenemies; i++)
{
GameObject enemy = Instantiate(Enemy, ShipSpawn.transform.position, Quaternion.identity) as GameObject;
enemy.name = "Enemy" + i;
Game_Manager.Enemies.Add(enemy);
Camera.main.GetComponent<Game_Manager>().CreateArrow(i);
yield return new WaitForSeconds(timebetweenspawn);
}
}
Game_Manager.Enemies
是Game_Manager
中的静态列表。
当敌人产生时,Camera.main.GetComponent<Game_Manager>().CreateArrow()
被调用,接下来是
public void CreateArrow(int enemyIndex)
{
EnemyDetection = new Ray(Player.transform.position, Enemies[enemyIndex].transform.position - Player.transform.position);
Vector3 raypoint = EnemyDetection.GetPoint(4);
Vector3 enemydirection = Enemies[enemyIndex].transform.position - Player.transform.position;
Quaternion rotation = Quaternion.LookRotation(enemydirection);
GameObject arrow = Instantiate(Arrow, raypoint, rotation) as GameObject;
arrow.GetComponent<Player_enemyArrow>().enemy = Enemies[enemyIndex];
print(enemyIndex);
print(Enemies[enemyIndex].name);
arrow.name = Enemies[enemyIndex].name + "Arrow ";
arrow.transform.SetParent(Player.transform);
arrow.transform.position = raypoint;
}
这会使敌人产生并创建一个带有Player_EnemyArrow
脚本的箭头,该脚本处理指向给定敌人和箭头的位置。
我的问题是第一个箭头工作正常,但是当我通过CreateArrow(1)
和i的1时,该指数中的敌人是敌人,当它应该是敌人时。