所以我有敌人从顶部坠落的危险,但我得到的GameObject[]不包含"长度错误"的定义,这里是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
public Transform[] spawnPoints;
public GameObject[] hazards;
private float timeBtwSpawns;
private float startTimeBtwSpawns;
// Update is called once per frame
void Update()
{
if(timeBtwSpawns <= 0)
{
Transform randomSpawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];
GameObject randomHazard = hazards[Random.Range(0, hazards.Lenght)];
Instantiate(randomHazard, randomSpawnPoint.position, Quaternion.identity);
timeBtwSpawns = startTimeBtwSpawns;
}
else
{
timeBtwSpawns -= Time.deltaTime;
}
}
}
Lenght
应拼写为Length
↓↓↓
GameObject randomHazard = hazards[Random.Range(0, hazards.Lenght)];
应该是
↓↓↓
GameObject randomHazard = hazards[Random.Range(0, hazards.Length)];
Quarternion.identity
应该显式引用其程序集。您可以使用UnityEngine.Quarternion.identity
来消除此调用的歧义。