kindly help me ,I have done all, but this error prevent me to play my own game, anyone code master kindly help , GmAddScore is not working ,
Public Void GmAddScore(){
this.myScore++;
}
and i call it on the obstacles script but unity shows all of the errors abour the same it dont adding the score , and dragon drops down and error generating continously please somebody help , its about my lots of struggle
GameObject.Find() searches for a GameObject in the scene that has the name you specify. You canât use it to find individual components like your GameManager script, you instead have to input the name of the GameObject that has the GameManager script attached to it.
It looks as though heâs using GetComponent in the call, too.
This was double posted. OP: Please donât double post.
I responded to this in âScriptingâ, I believe.
Edit: Correction, sorry⌠the post to which I responded was a reply to an older thread (posted as a question*).
Is the name of your Text item âTextâ in the Hierarchy window? Whatever the name of the Gameobject is there, is what Unity will search for, in the scene.
@HaddicusGames yes text is sub-object of the gameobject convas for UI, To show the public text in the game
Bro!!!
What to do now!
Should i change the gameobject or in the base Gameobject.Find(), individually calling the components isânt the right option!
But gamemanager=Gameojbect.Find(âGame Managerâ).GetComponent() ;
Through it i call
Void AddScore() {
gamemanager.GmAddScore();
}
Aaaaahhhhh
Well, donât freak out⌠What is null: the text object or the game manager? It should tell you in the console where the error is and you can double click to open it at that spot.
Just ensure that whatever is there isnât null.
@methos5k see this s.s !
dragon falls down , and down down down down nd so on ⌠to hell huh !!!
Do you find the game object in Awake?
void Start(){
myScore = 0;
myScoreGUI = GameObject.Find (âTextâ).GetComponent ();
InvokeRepeating (âObstacleSpawnerâ, .5f, 1.5f);
}
public void GmAddScore(){
this.myScore++;
myScoreGUI.text = myScore.ToString();
}
I meant the game manager being foundâŚ
NullReferenceException: Object reference not set to an instance of an object
ObstacleScript.AddScore () (at Assets/Scripts/ObstacleScript.cs:38)
ObstacleScript.Update () (at Assets/Scripts/ObstacleScript.cs:28)
this is the error!
it cannot find the object from gamemanager script and error generated in obstaclescript