(question has been answered)
I have this code...
var selected : boolean;
var selectedObject : GameObject;
var oldObject : GameObject;
var xcoord : float;
var zcoord : float;
function Update()
{
if(selectedObject != null)
{
xcoord = selectedObject.transform.position.x;
zcoord = selectedObject.transform.position.z;
if(selectedObject.tag == "Unit")
{
print(selectedObject.name + " selected");
oldObject = selectedObject;
}
if(selectedObject.tag == "Tile")
{
if(oldObject.tag == "Unit")
{
print("went through");
/*oldObject.transform.position.x = xcoord;
oldObject.transform.position.z = zcoord;*/
selectedObject = oldObject;
}
}
}
}
The problem is that 'went through' is never being printed. It seems that oldObject is not keeping its tag. Help please? I don't want to just reassign the tag, as I want it to keep its other components as well.
Edit: I put in the entire script to make it more readable. Edit2: Apparently something went wrong with my tagging, and it works now. The code above is (except for the null reference exception) fine.