我一直在尝试通过创建一个简单的跑步游戏来学习 Unity 3D。游戏从资产商店衍生出一条简单的道路。我决定在这条路上添加一些障碍物并从中制作一个预制件,但是当我将该预制件添加到一个数组中时,Unity 从中获取预制件来实例化它们并运行游戏,没有预制件被实例化。这是我的代码:using System.Collections;using System.Collections.Generic;using UnityEngine;public class TileManager : MonoBehaviour{public GameObject[] amountOfPrefabs;private Transform playerTransform;private float spawnZ = 0.0f;private float tileLength = 30.0f;private int amnTileOnScreen = 7;// Use this for initializationvoid Start(){ playerTransform = GameObject.FindGameObjectWithTag("Player").transform; for (int i = 0; i < amnTileOnScreen; i++) { SpawnTile(); }}// Update is called once per framevoid Update(){ if (playerTransform.position.z > (spawnZ - amnTileOnScreen * tileLength)) { SpawnTile(); }}private void SpawnTile(int prefabIndex = -1){ GameObject go; go = Instantiate(amountOfPrefabs[0]) as GameObject; go.transform.SetParent(transform); go.transform.position = Vector3.forward * spawnZ; spawnZ += tileLength;}}请帮我。
添加回答
举报
0/150
提交
取消