duojiduojiduoji295 2023-02-16 18:01 采纳率: 95%
浏览 11
已结题

unity脚本编程报错CS0311


using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class RandomPlace : MonoBehaviour

{

    public Transform[] SpawnPoints;//存放生成位置

    public GameObject[] prefab;//生成的物体



 



    public float spawnTime = 3f;//多长时间后调用

    public float nextSpawnTime = 2f;//下一个物体生成的时间



    // Start is called before the first frame update

    void Start()

    {

        InvokeRepeating("SpawnPrefab", spawnTime, nextSpawnTime);

        //"SpawnPrefabs" : 调用的方法名称

        //spawnTime: 多长时间后调用

        //nextSpawnTime: 下一个物体生成的时间

    }

    private void SpawnPrefab()

    {

        int Index = Random.Range(0, SpawnPoints.Length);//生成位置数组下标

       

        //随机生成一个数组的下标

        Instantiate(prefab, SpawnPoints[Index].position, SpawnPoints[Index].rotation);

        //prefab: 生成的物体

        //SpawnPoint[Index].position: 生成的物体所在的位置

        //SpawnPoint[Index].rotation: 生成物体的角度

    }

}

报错的是:Assets\RandomPlace.cs(55,9): error CS0311: The type 'UnityEngine.GameObject[]' cannot be used as type parameter 'T' in the generic type or method 'Object.Instantiate(T, Vector3, Quaternion)'. There is no implicit reference conversion from 'UnityEngine.GameObject[]' to 'UnityEngine.Object'.

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 2月25日
      • 已采纳回答 2月17日
      • 创建了问题 2月16日

      悬赏问题

      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号
      • ¥15 利用kmeans或kshape聚类分析对归一化的无量纲时间-降雨序列进行聚类