Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Raviraja190 · Oct 25, 2016 at 12:34 PM · objectinstanceobject reference

“Object reference not set to an instance of an object

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class PlayerScoreScript : MonoBehaviour {

 [SerializeField]
 public AudioClip  coinClip, lifeClip;
 private CameraScript CameraScript;
 private Vector3 previousPosition;
 private bool countScore;

 public static int scoreCount;
 public static int lifeCount;

 public static int coinCount;

 void Awake(){
     CameraScript = Camera.main.GetComponent<CameraScript> ();
 }


 // Use this for initialization
 void Start () {
     previousPosition = transform.position;
     countScore = true;

 }

 void Update () {
     CountScore();
 }

 void CountScore (){
     if(countScore){
         if(transform.position.y < previousPosition.y){
             scoreCount++;
         }
         previousPosition = transform.position;
         GamePlayController.instance.SetScore (scoreCount);
     }
 
 }
 // Update is called once per frame



         void OnTriggerEnter2D(Collider2D target){
             if(target.tag =="Coin"){
                 coinCount++;
                 scoreCount+=200;
                 AudioSource.PlayClipAtPoint(coinClip,transform.position);
                 target.gameObject.SetActive(false);

         GamePlayController.instance.SetScore (scoreCount);
         GamePlayController.instance.SetCoinScore (coinCount);
         }
             if(target.tag =="Life"){
                 lifeCount++;
                 scoreCount+=300;
                 AudioSource.PlayClipAtPoint(coinClip,transform.position);
                 target.gameObject.SetActive(false);
         GamePlayController.instance.SetScore (scoreCount);
         GamePlayController.instance.SetLifeScore (lifeCount);
             }

             if(target.tag=="Bounds"){
                 CameraScript.moveCamera=false;
         countScore=false;
         transform.position=new Vector3(500,500,0);
                 lifeCount--;

         GamePlayController.instance.GameOverShowPanel(scoreCount, coinCount);
         GameManager.instance.checkGameStatus (scoreCount, coinCount, lifeCount);
             }
             if(target.tag=="Deadly"){
                 CameraScript.moveCamera=false;
         countScore=false;
         transform.position=new Vector3(500,500,0);
                 lifeCount--;
         GamePlayController.instance.GameOverShowPanel (scoreCount, coinCount);
         GameManager.instance.checkGameStatus (scoreCount, coinCount, lifeCount);
             }

} }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raviraja190 · Oct 25, 2016 at 12:35 PM 0
Share

Problem is on Line 34

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AurimasBlazulionis · Oct 25, 2016 at 12:49 PM

I believe the error is that a static variable instance is not set to anything. In any GamePlayController component, in Awake method, call instance = this

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Raviraja190 · Oct 25, 2016 at 01:02 PM 0
Share

i Did It public static GamePlayController instance;

 [SerializeField]

 public Text scoretext, cointext, lifetext, gameOverScoreText, gameOverCoinText;

 [SerializeField]
 public GameObject pausePanel, gameOverPanel;

 [SerializeField]
 public GameObject ReadyButton;



 // Use this for initialization
 void awake() {
 
     $$anonymous$$akeInstance ();

 }

 void start(){
     Time.timeScale =0f;
 }
 
 // Update is called once per frame
 void $$anonymous$$akeInstance () {
 
     if (instance = null) {

         instance = this;
     }
 }

 public void GameOverShowPanel (int finalScore, int finalCoinScore){
     


     gameOverPanel.SetActive (true);
     gameOverScoreText.text = finalScore.ToString ();
     gameOverCoinText.text = finalCoinScore.ToString ();
     StartCoroutine(GameOverLoad$$anonymous$$ain$$anonymous$$enu());
         }

         IEnumerator GameOverLoad$$anonymous$$ain$$anonymous$$enu(){
             yield return  new WaitForSeconds(3.0f);
             Scene$$anonymous$$anager.LoadScene("$$anonymous$$ain$$anonymous$$enuScene");
         }

 public void PlayerDiedRestartTheGame(){
     StartCoroutine (PlayerDiedRestart ());
 }

 IEnumerator PlayerDiedRestart(){
     yield return new WaitForSeconds (1f);
     Scene$$anonymous$$anager.LoadScene ("Gameplay");
 }

 public void SetScore(int Score){
     scoretext.text = "x" + Score;
 }
 public void SetCoinScore(int CoinScore){
     cointext.text= "x" + CoinScore;
 }
 public void SetLifeScore(int LifeScore){
     lifetext.text =  "x" + LifeScore;
 }

 public void PauseTheGame(){

     Time.timeScale = 0f;
     pausePanel.SetActive (true);
 }

 public void ResumeGame(){
     Time.timeScale = 1f;
     pausePanel.SetActive (false);
 }
 public void QuitGame(){
     Time.timeScale = 1f;
     Scene$$anonymous$$anager.LoadScene ("$$anonymous$$ain$$anonymous$$enuScene");
 }
 public void StartTheGame(){
     Time.timeScale = 1f;
     ReadyButton.SetActive (false);
 }


 }
avatar image AurimasBlazulionis Raviraja190 · Oct 25, 2016 at 01:23 PM 0
Share

It has to be Awake, not awake. Everything is case sEnsItiVe.

avatar image Raviraja190 AurimasBlazulionis · Oct 25, 2016 at 01:33 PM 0
Share

Yes I have changed now but The Same Problem

Show more comments
Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

79 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make an object follow another regarding its rotation 0 Answers

Object reference not set to an instance of an object 2 Answers

Windows Mixed Reality UWP Compilation Error 0 Answers

How to Fix this issue 1 Answer

How do I fix a Null Reference Exception (object reference not set to an instance of an object)? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges