Question by
MostWanted · Sep 13, 2016 at 05:31 PM ·
instantiate prefab
I wrote a script for instanciating a prefab after ontriggerexit() function, but it is instanciated to with a variation in position.y from the empty gameobject i placed - where it should be instanciated
@micheal `using UnityEngine; using System.Collections;
public class FloorSpawner :MonoBehaviour {
public GameObject[] TileArray;
public GameObject CurrentTile;
private static FloorSpawner instance;
public static FloorSpawner Instance
{
get
{
if (instance==null)
instance=GameObject.FindObjectOfType<FloorSpawner>();
return instance;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Spawn()
{
int num = Random.Range (0, 2);
CurrentTile = (GameObject)Instantiate(TileArray[num],CurrentTile.transform.GetChild(0).transform.GetChild(num).position ,Quaternion.identity);
}
}'
using UnityEngine; using System.Collections;
public class Trigger : MonoBehaviour {
void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
FloorSpawner.Instance.Spawn();
}
}
}
Comment