GameObject not Spawining

本文关键字:Spawining not GameObject | 更新日期: 2023-09-27 18:04:43

我正在用unity制作一款俄罗斯方块游戏,但这段代码并没有生成我的俄罗斯方块。我已经将我的游戏对象分配给group[]数组。

这是我的代码:

using UnityEngine;
using System.Collections;
public class Spawner1 : MonoBehaviour {
    public GameObject[] group;
    void start(){
        SpawnNext ();
    }
    void SpawnNext(){
        Instantiate(group[Random.Range(0,group.Length)],new Vector2(5.0f,10.0f),Quaternion.identity);
    }
}

GameObject not Spawining

它没有生成,因为您在start中使用了小写的s。这应该是Start,而不是start。请修复这个问题,你的对象现在应该开始产卵了。

public class Spawner1 : MonoBehaviour {
    public GameObject[] group;
    void Start(){
        SpawnNext ();
    }
    void SpawnNext(){
        Instantiate(group[Random.Range(0,group.Length)],new Vector2(5.0f,10.0f),Quaternion.identity);
    }
}