- Home /
Unity Crashes on Mac OSX when ever I try to Assign a Text Value inside a property.
I am facing a pretty weird issue in Unity. Whenever I Use a statement Like this.
public Text scoreText;
public int score
get{
return score;
}
set{
score = value;
scoreText.text = value.ToString();
}
Unity Crashes and OSX default Error Message appears to submitt crash report. Any one facing this issue?
Answer by Landern · Apr 27, 2015 at 07:06 PM
You're not using c# properties correctly. If you're going to do something like you posted, you should have a backing field and not return it's self, because thats no good. Auto Properties are implemented under the covers as two methods with a backing field to contain the data. You should create a backing field like:
public Text scoreText;
private int _score;
public int score {
get{
return _score;
}
set{
_score = value;
scoreText.text = value.ToString();
}
}
you are also missing the open and closing curly braces that belong to the property it self.
Your answer
Follow this Question
Related Questions
unity 5 crashing when downloading from asset store 0 Answers
Unity editor keeps on crashing 1 Answer
Massive problem updating to Unity 2019.1 0 Answers
Unity Crashing 0 Answers
why does Unity keep crashing 0 Answers