Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Classify delivery styles by type.

Answered: 1 week ago