- Home /
Empty Transform just attaches itself to an a prefab?
So I asked earlier to see if something was wrong with my code because initially the tiles wouldn't move at all. Well I solved that bit but now instead of all the tiles moving the Empty transform just seems to attach itself to a random Tile. When I click any of the adjacent tiles the tile I click gets shoved behind the tile the transform attached itself to.
I can't seem to pinpoint whats causing this any help would be awesome. Here's the code: #pragma strict
var Temp : Transform;
var Empty : Transform;
var Tile : GameObject;
function Start(){
Tile.transform.position = transform.position;
Empty.transform.position = transform.position;
Temp.transform.position = transform.position;
}
function OnMouseUp(){
if (Vector3.Distance(transform.position,Empty.position)==1){
Temp.transform.position = Empty.transform.position;
Empty.transform.position = Tile.transform.position;
Tile.transform.position = Temp.transform.position;
}
}
Would it be possible for you to post an image of what you are trying to accomplish as far as the movement goes? I'm having a tough time visualizing what you are trying to do here.
And if you can, possibly an image showing what is happening currently (the behavior you don't want). The transform isn't going to randomly attach itself to another object, so something about the behavior makes it look like that is happening when that probably isn't exactly the case.
Ok so when I put down the tile and set all the transforms and objects into the right slots on the Tile's scripts it looks like this before running it: Then when I run it the transform puts itself on the bottom left block:
And finally when you actually click on a block it looks like it just moves behind the bottom left block:
And what is the behavior you are looking for? Are you wanting those two bottom blocks to switch places? Also, what is your script attached to?
Well my scripts are attached to a Prefab, the tiles. The actions I want is that the cubes switch places with the "Empty" transform, leaving a new empty spot to be switched with. But what happens is the "Empty" transform hovers over a block, and if I delete said block it hovers over a new one. But when it hovers over a block that block never moves the entire game.
Do you want this to happen on mouse up? It looks like both of those tiles are the same distance from the empty tile. If that is the case the swap will either get called on both tiles or neither which I don't think is what you want. If both tiles are the same distance and you only want to move one, how do you want the decision to be made on which tile gets moved?
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Script Doesn't work as intended 1 Answer
Setting Scroll View Width GUILayout 1 Answer
UnassignedReferenceException 1 Answer