Reputation: 63
I know this is asked a lot but its a very broad error so i need some help with how to make my vector3 static.
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Grid.GridScan(transform.position);
}
}
"GridScan" is called from here:
public void GridScan(Vector3 worldposition)
{
Debug.Log(GetValue(worldposition));
if ((GetValue(worldposition)) == 100)
{
if (Neighbours(worldposition, 2) < 2)
{
SetValue(worldposition, 0);
}
if ((Neighbours(worldposition, 2)) > 3)
{
SetValue(worldposition, 0);
}
}
if ((GetValue(worldposition)) == 0)
{
if (Neighbours(worldposition, 2) == 3)
{
SetValue(worldposition, 100);
}
}
}
The error is for the first code and for Grid.GridScan(Vector3)
. The first code is attached to many game objects as they are created. How do I make the vector3
(transform.position
) static?
Upvotes: 0
Views: 166
Reputation: 12608
The error is because the GridScan method is not static, you need to call this on a particular grid. You can add the static modifier to make it static.
Alternatively you can make Grid a singleton, which means having a static property pointing to the current grid. In Unity you can also use FindObjectOfType to search for it in the scene, however this is an expensive operation. It has to go through all objects in the scene to find your script, thats much more expensive than getting a static property.
Upvotes: 1