Hi all
Ive been at this for a day now. Racking my brain trying to get what I can see on paper working in Unity.
Ok…imagine this:
I have a row of 10 tiles across the screen (0 to 9), if the user clicks a tile it destroys it and the other tiles fill the gap.
Thats the logic. Trying to get it to work is something else.
On the tile that is clicked there is a script called DestroyMe.js
which contains the following:
function OnMouseUp(){
Debug.Log("Sending Kill for " + gameObject.name);
MainSetup.deleteTile(gameObject);
}
That is calling MainSetup.deleteTile()
Which has the following code in it:
static function deleteTile(name : GameObject){
var i = 0;
var n = 0;
var targetPos;
var targetPlaceHolder;
var aName = "";
Debug.Log("killing " + name.name);
Destroy(name);
// yield WaitForSeconds(1);
Debug.Log("continuing....");
for (i=0 ; i <9; i++)
{
aName = "TileCopy" + i;
Debug.Log("aName = " + i);
if(GameObject.Find(aName) == null)
{
Debug.Log("Found Empty Space at " + i);
targetPlaceHolder = "s" + i;
targetPos = GameObject.Find(targetPlaceHolder).transform.position;
Debug.Log("Target Position is" + targetPos);
for (n=i; n<=9;n++)
{
Debug.Log("Looking for next filled tile.." + n);
aName = "TileCopy" + n;
if(GameObject.Find(aName) != null)
{
Debug.Log("Found filled tile at " + n + ", everything ready to move....");
Ani.Mate.To(GameObject.Find(aName).transform,0.1, {"position": targetPos, "direction": EasingType.InOut});
}
}
return; // one tile should have moved by now.
}
}
}
Now, if i run this then the console outputs “Sending Kill for” and the tile you clicked on,
What should happen is the tile gets deleted and the other tiles fill the gap.
If I rem out
Destroy(name);
Then the code runs and the console fills up with all the details from ALL the Debug.Logs but the clicked on tile hasnt had time to be destroyed so the actual code doesn’t do what its supposed too
So I added:
yield WaitForSeconds(1);
Which doesn’t work, it stops the entire script from running. Not even the Debug.Log("killing " + name.name); gets run.
So, anybody help me here would be very very appreciated.
Thanks