I am facing a weird issue where my Getter always returns 0. Here is my code:
Setting the spawn position works but getting the spawn position always returns 0. Why?
public class Tile : MonoBehaviour
{
[SerializeField] string tileName;
int spawnPosition;
public string GetTileName()
{
return tileName;
}
public int GetSpawnPosition()
{
print("returned: " + spawnPosition);
return spawnPosition;
}
public void SetSpawnPosition(int spawnPosition)
{
this.spawnPosition = spawnPosition;
print("set to: " + this.spawnPosition);
}
private void Update()
{
print("DANIEL" + spawnPosition);
}
}```
`print("DANIEL" + spawnPosition);` always prints DANIEL0 and `print("returned: " + spawnPosition);` always prints returned 0
The weird thing is that `print("set to: " + this.spawnPosition);` prints the correct value.
The EVEN WEIRDER thing is that when I make spawnPosition public it WORKS even though I never access it directly, only through the Getter method.
**Can anybody explain this to me?**
