返回

c#-如何告诉另一个脚本在 Unity 中实例化一个特殊的预制件?

发布时间:2022-09-07 03:39:05 385
# flask

我有生成障碍顺序的代码:

using UnityEngine;
using System.Collections.Generic;

public class GroundSpawner : MonoBehaviour
{   
    public GameObject groundTile;
    public static string item;

    private List listOfChoices = new List{"box", "antitank", "barricade", "wheels"};
    private List roadList = new List();

    Vector3 nextSpawnPoint;

    void Start()
    {
        roadList = GenItemList(10, 2);
        for (int i = 0; i < roadList.Count; i++)
        {
            item = roadList[i];
            GameObject temp = Instantiate(groundTile, nextSpawnPoint, Quaternion.identity);
            nextSpawnPoint = temp.transform.GetChild(1).transform.position;
        }
    }

    public List GenItemList(int numOfItems, int numOfTanks)
    {
        List returnList = new List();

        for (int i = 0; i < numOfItems; i++)
        {
            int randomIndex = Random.Range(0, listOfChoices.Count);
            string add = listOfChoices[randomIndex];
            returnList.Add(add);
        }

        for (int i = 0; i < numOfTanks; i++)
        {
            int randomIndex = Random.Range(1, numOfItems);
            returnList[randomIndex] = "tank";
            int tankIndex = randomIndex;

            int numOfMolotoves = Random.Range(1, 4);
            for (int j = 0; j < numOfMolotoves; j++)
            {
                randomIndex = Random.Range(0, (tankIndex - 1));
                if(returnList[randomIndex] != "molotov")
                {
                    returnList[randomIndex] = "molotov";
                }
                else
                {
                    numOfMolotoves++;
                }
            }
        }

        return returnList;
    }

}

void Start()有一句话:

item = roadList[i];

这条线是我想要制造的障碍物(盒子、路障、轮子、反坦克或燃烧弹)。

我有GroundTile那已经GroundTileScript.我举例说明GroundTile,但我该如何判断电流GroundTile例示item从…起GroundScript? 真的有可能吗?

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(2)
按点赞数排序
用户头像