Hello all ,
I’m new in unity. Got stuck with a certain problem. I want to create an endless runner platform generation script.The basic logic that i want to implement is that
1.Each platform has a collider frame in the middle.
2.Upon triggering a collision the next platform will get generated having similar collider in the middle.
3.Thus the script aims to keep on generating a new platform as the colliders are hit in successsion.
#pragma strict
var prefabPlatform : GameObject = Platform ;
var testvalue: int =5 ;
function Start () {}
function Update () {}
function OnTriggerEnter (other : Collider)
{
var new_prefab : GameObject;
var childObject=other.gameObject;
print(other.gameObject.name+" with tag: "+other.gameObject.tag+" has hit the "+gameObject.name);
if(other.gameObject.tag.Equals("runner"))
{
new_prefab=Instantiate(prefabPlatform, Vector3(0, 0, -1*20), Quaternion.identity);
print("instantiating prefab: ");
}
else
print("Wrong Hit !!!");
}
Where i am stuck is For the second gameobject that is generated how do i set the prefabPlatform to dynamically get assigned to a random prefab ?
Basically i want to var prefabPlatform : GameObject =(Some Code to set a random prefab from a list of prefabs i have made )