- Home /
Script Doesn't work as intended
Ok, so I have this code that I've finally kinked all the bugs out of. But after all that the code doesn't work exactly as intended.
firstly I have 3 "tiles" I want to be able to move by swapping it with an empty transform. But instead of them swapping the "tile" just moves over to the empty transform and the transform doesn't move to allow for other "tiles" to switch to it.
Here's the Code:
#pragma strict
var Empty : Transform;
var Tile : GameObject;
function Start(){
Tile.transform.position.y = transform.position.y;
Tile.transform.position.x = transform.position.x;
Empty.transform.position = transform.position;
}
function OnMouseUp(){
if (Vector3.Distance(transform.position,Empty.position)==1){
Tile.transform.position = Empty.transform.position;
Empty.transform.position = Tile.transform.position;
}
}
Any help would be awesome.
Answer by calebheale · Jul 21, 2014 at 07:08 PM
It looks like you are assigning the value in Empty to the Tile transform and then assigning the value in Tile back to Empty, which essentially does nothing other than overwrite what was originally in Tile. If you are trying to swap the two you should use an additional transform to store one of the values in the interim.
pseudocode:
temp = empty
empty = tile
tile = temp
Thanks that worked perfectly, but now an odd new problem has shows its face. When I run the game Empty seems to go down one in the X axis. I'm not sure whats causing this. Any insight?
I was wrong ins$$anonymous$$d of the transform moving down it just seems to attach it'self to the nearest/lowest tile in the game... oh boy this'll be fun.
Your answer
Follow this Question
Related Questions
Mecanim not updating script when it switches state? 2 Answers
Attack Animation through Javascript 0 Answers
Playing a second idle animation... 1 Answer