-1
我正在製作一個帶有4個預製「塊」的十字路口遊戲,當玩家碰到名爲的對撞機時,我想創建這些「塊」。我的代碼隨機化了哪個塊在玩家點擊時加載,然後產生下一個塊。由於某些原因,它不能識別我的預製件,並且我想在最後一個之前加載塊25 z值。代碼:實例化一個預製?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChunkLoader : MonoBehaviour {
int level = 0;
public Transform chickenpos;
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
void spawnChunk()
{
float chunkload = Random.Range(0, 2);
Debug.Log(chunkload);
if (level <= 10)
{
if(chunkload <= 1)
{
Instantiate (ChunkA1, chickenpos);
}
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Loader")
{
level = level++;
Debug.Log(level);
spawnChunk();
}
}
}
這樣做不會**很好地描述你的問題,但你似乎在引用一個甚至沒有聲明的變量('ChunkA1')。 – Programmer
在這種情況下,我會引用你到[C#教程](https://unity3d.com/learn/tutorials/s/scripting)。請參閱**變量和函數**主題。 – Programmer