Quantcast
Viewing latest article 5
Browse Latest Browse All 16

Unity C# Can't update variables in other scripts

Hello! I have now been sitting for the last two hours trying to figure out how I can solve this problem of mine. You see, I am currently making a game where the purpose of the game is to make the player able to select his level - depending on which levels he has unlocked. So basically I have set a trigger for the "teleportation object", with name "tp1". I know you may find some of my code rather odd, but that's not the problem. The problem is to access the class. My script is as follows; public PlayerClass pc; void Start() { pc = new PlayerClass(); } void OnMouseOver() { if(this.gameobject.name == "tp1" && gameisTrigger == true && hasuLockedlvl1 == true) { //teleport player } } Even though I play and "unlocks level 1", and updates the variable from another script it doesn't seem to update here. And another script I have the following when the player actually unlocks the level 1; public PlayerClass pc; void Start() { pc = new PlayerClass(); } void Update() { if(playerhasDoneSomething == true) { pc.level = 2; } } The problem is that it doesn't seem to update the class, so if I call a debug after I have changed the value inside the class - it is updated. However, the other object that manages the "access" to the other levels doesn't seem to update. Here is my PlayerClass by the way; private int level; public int Level { get{return level;} set{level = value;} } I would really appreciate if some of you could help me out with this problem. Thanks in advance.

Viewing latest article 5
Browse Latest Browse All 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>