- Home /
I figured out the problem.
Space Shooter No Definition
I'm writing the tutorial space shooter, and I am attempting to use the method AddScore from the GameController class.
Here is the method:
public void AddScore(int newScoreValue) {
score += newScoreValue;
UpdateScore ();
}
Then, in the DestroyByContact class i am trying to access it like this:
public GameController gameController;
public int scoreValue;
gameController.AddScore (scoreValue);
In the console this error reads:
Assets/Scripts/DestroyByContact.cs(23,32): error CS1061: Type `GameController' does not contain a definition for `AddScore' and no extension method `AddScore' of type `GameController' could be found (are you missing a using directive or an assembly reference?)
Anyone know why this might be? thanks
gameController.AddScore (scoreValue); is not in a function ? If so, obviously, put it in a function ....
Have you imported the GameController namespace as suggested ?
Answer by Ali-hatem · Mar 24, 2016 at 10:44 AM
public class DestroyByContact : MonoBehaviour {
GameController gameController;
GameObject obj;
public int scoreValue;
void Start(){
obj = GameObject.Find ("the name of the object that GameController script attached to");
if (obj != null) {
gameController= obj.GetComponent<GameController > ();
gameController.AddScore (scoreValue);
}
else {
print ("no object with the given name found did you gave the exact name");
}
}
}
i can give you other solution by cheeking tag ins$$anonymous$$d of name but i don't know what are you trying to do what will happen if score variable was different in each object what scoreValue variable will be so if it not necessary put the score & the function you try to call in one object . but if you have other plain tell me what's going on!
Well, the score value is that same, but I don't want collisions between obstacles cause an increase in the score, only when the player shoots and hits.
Follow this Question
Related Questions
Unity keeps freezing every time I enter playmode!!! Help!! 1 Answer
Mouse Look / Cursor 1 Answer
How to remove floating 0 Answers
open door to next level, after 10000 points were added to your score (solved) 2 Answers
Problem with a score script 1 Answer