Question: I have a game and it shows me this error Object reference not set to an instance of an object Game.Start() when moving to

I have a game and it shows me this error Object reference not "set to an instance of an object Game.Start() " when moving to the next page and it appears that the reason for the error is this command: anim =character.GetComponent(); Here is my code:

public class game: MonoBehaviour { public AudioSource A, b; [SerializeField] private string SceneNameToLoading; public GameObject character; Animator anim;

void Start() { A.Play(); b.Stop(); anim = character.GetComponent();//the error here in that line }

public void win() { b.Play(); A.Stop(); anim.SetBool("walk", true); GiveSticker(); StartCoroutine("nextlevel");

} public void loss() { anim.SetBool("cry", true); }

IEnumerator nextlevel () { yield return new WaitForSeconds(5); SceneManager.LoadScene(SceneNameToLoading); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!