Find a specific object using transform
Hey all. I really wish I didn't have to ask this because my code is quite long and complicated, but I've been struggling with this for three days now and am getting a little impatient. My game involves a cube and some nodes. Each node contains a 'Node' script. I've made it quite far now but one part of my code is suddenly not working as it should be.
if (PlayerMovement.playerMoved == true)
{
//Debug.Log("b");
if (player.transform.position - playerOffset == this.transform.position)
{
//Debug.Log("a");
gameMaster.currentNode = this.gameObject;
PlayerMovement.playerMoved = false;
}
}
This code is taken from the 'Node' script and is used to determine what node the player is currently on by using a variable called 'currentNode'. For some reason when entering some nodes, it won't update, while other times it updates fine. By the way, I'm pretty certain that 'player.transform.position - playerOffset' does equal a node. I think that my problem here lies in the 'this.transform.position', or the 'this.gameObject'.
Basically I just want a way to avoid using 'this' as I think it's getting mixed up with the other nodes. Anyone know of a better way I can do this. I was thinking about adding all the objects with the script 'Node' attached to an array or something and then using some code that finds the currentNode from the array but I have no idea how I would do that. Any ideas before I go insane? :D Thanks everyone.