Hey guys,
This question comes in completion of my previous one “How to limit instantion of prefabs/gameobjects”.
So I have a script called “CreateWall” that I use to instantiate objects in certain directions on mouse click&drag.
The instantiation code looks something like this:
function SpawnFence()
{
if (sss == 1 && !someCol.someBool)
{
position_var = clone2.position + Vector3(0,20,0);
clone3 = Instantiate(wallObject, position_var, Quaternion.identity);
clone3.parent = parentofwall;
clone3.transform.position.z = 0;
last_clone = clone3;
if(!someCol.someBool){
sss = 2;
}
}
and it goes on and one until the last clone.
The collision script is currently set on the object that is being instantiated and it has the following code:
function Awake()
{
wallCreate = GameObject.Find("Background - GameManager").GetComponent.<CreateWall>();
someBool = false;
}
function OnTriggerEnter(hit:Collider)
{
if(hit.collider.tag == "SomWall")
{
wallCreate.sss = 0;
Debug.Log ("collided");
someBool = true;
}
}
Here’s my problem. The sss var is being set to 0 in my CreateWall, my someBool is becoming true right when colliding but i think objects are instantiating too fast for the script to have time to run through this. Should I slow it down using WaitForSeconds or should I rewrite my whole script?
SEE LAST COMMENT FOR MORE INFO ON THE FIX!