- Home /
Cannot change method name in a class.
I have a class class called ScoreKeeper , and another class called EnemyBehaviour.
Inside ScoreKeeper i have:
public void Score(int points){
score=score+points;
myText.text=score.ToString ();
}
Inside EnemyBehaviour I have:
public ScoreKeeper scoreKeeperObj;
void Start(){
scoreKeeperObj = GameObject.Find ("Score").GetComponent<ScoreKeeper>();
}
Whenever I change my method name from Score to something else.. In both classes of course.. I get nullReferenceException .. Why is that happening.. Is the method Score , reserved in Unity ?
Answer by $$anonymous$$ · Jun 03, 2015 at 02:01 PM
I presume the ("Score") is a gameObject in scene with your Scorekeeper script, correct?
if yes then you'll call the Score function by:
scoreKeeperObj.Score(100);
Your answer
Follow this Question
Related Questions
error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers
Displaying a static variable from another script with OnGUI 1 Answer
Why won't my script load? 1 Answer
"Object reference not set to an instance of an object" problem 1 Answer
error CS0118: `New_Career.Fame' is a `field' but a `type' was expected 1 Answer