Just for reference I’m total noob.
I’m assigning to local string variable a pubic variable from another class through its instance:
public class OnScreenThing : MonoBehaviour
private void OnGUI()
{
var Line1 = GameManager.instance.SomePubVar.ToString();
Gui.Label(rec new, + "Blah1" + Line1)
}
}
My problem is that if I do analyze of the “SomePubVar” it is not listed as being assigned by OnScreenThing but it should not, I just read it. How do i avoid this?
Are you asking if you changed the value of SomePubVar after calling ToString() on it?
If so, don’t worry, you didn’t change it, you just created a string from it as a new variable. SomePubVar hasn’t changed.
To be absolutely sure that SomePubVar can’t be accidentally changed, you could make it a read-only property:
public class GameManager : MonoBehaviour
{
public float SomePubVar {get; private set;}
}
Note that “set” is private. This makes it so only GameManager can change it.
Yeah, I understand that, just wanted to make sure.
I guess my question was more why does code analyzer says the variable is being assigned by that class. The funny thing is that not every of these SomePubVar are shown like that.