Advertisemen
Unity 3D Make Mystery Box
Spawn random prefab on trigger enter
DIRECT DOWNLOAD HERE
THIS IS BACKUP IN TEXT FORM
1. Create New C# and name it : itemSpawner
2. Copy & Past this text and save C# :
---------------------------------------------------------------------------------
using UnityEngine;
using System.Collections;
public class itemSpawner : MonoBehaviour {
bool hasSpawned = false;
public GameObject[] itemPrefabs;
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
if(!hasSpawned)
{
hasSpawned = true;
Spawn();
}
}
}
void Spawn()
{
Instantiate(itemPrefabs[Random.Range(0,itemPrefabs.Length)],transform.position, transform.rotation);
}
}
---------------------------------------------------------------------------------
Advertisemen
Tidak ada komentar:
Posting Komentar