Unable to access object that I have a should have a reference to.

Hey guys, this is just a quick question to fix a silly mistake I made.

public static void FindAdjacents()
	{
		print (Manager_Levels.tilesAll[1].transform.position);
		foreach (Tile_Levels FindAdjacentTile in Manager_Levels.tilesAll) {
			
			//toplayer
			if (FindAdjacentTile.transform.position == new Vector3 (transform.position.x - 1, transform.position.y + 1, transform.position.z + 1))

`` { tileUpFwdLft = FindAdjacentTile;}

so this is just a small excerpt of my script so you can see what’s happening, findAdjacents() is called by my otherscript Manager_Levels, findAdjacents() then grabs an array in Manager_Levels to use the arrays components to findout if one of the components in the array is at a certain position. But what my problems is, is that my print() is showing the transform position of component [1] in the array, but in the foreach loop it says that i need a reference to access component.transform.

That’s my question, I hope it wasn’t too messy or unclear
thanks for your help :slight_smile:

The problem is the method is a static, which means it’s not actually attached to any object. Static variables/methods are owned by the class as a whole instead of each object having it’s own copy. This means you can’t use the ‘transform.position.x’ and such to make the new Vector3.

If the function needs to be static, then you’ll either need to pass a Vector3 to the FindAdjacents() method, or grab it inside the method from a live object.

Thank you so much for your help, your solution is what i thought it’d be. I’m very greatful, thanks again. :slight_smile: