游戏对象[]"不包含"Lenght Im试图制作闪避游戏并为其制作生成器"的定义,但我收到此错误



所以我有敌人从顶部坠落的危险,但我得到的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来消除此调用的歧义。

相关内容

  • 没有找到相关文章

最新更新