• 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 /
This question was closed Nov 25, 2015 at 06:26 PM by Blade666 for the following reason:

no help was given

avatar image
Question by Blade666 · Nov 12, 2015 at 08:07 PM · javascripterrorscript.nullreferenceexceptioncoin

Help with JS script

I recently got some help with this script but now it is playing up again so i am back for more help It is giving me the error

 NullReferenceException: Object reference not set to an instance of an object
 Coin.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Coin.js:11)

which means it is not being called or something like that but i dont know why here is the two scripts

Coin script:

 #pragma strict
 
 var Money : MenuShopSystem ;
 functi

on Start () {

}

function OnTriggerEnter2D (other: Collider2D) { Debug.Log ("Touch"); Money.Money += 100; Destroy(gameObject.Find("Coin"));

}

Shop script (what the coin script is calling from)

     #pragma strict
     //add this script to any gameObject you want//
     
     
     
     //paste this to add more items to youre shop:
     // if(GUI.Button(Rect(Screen.width/2,Screen.height/2,150,150), Item)){
     // if(Money >= 200){
     // Money -= 200;
     // }else{
     // Money -=0;
     // }
     // }
     // GUI.Button(Rect(Screen.width/2+150,Screen.height/2,150,150), "Buy: 200");
     
     
     
     //variables----------------------------------------
     var ShowShop = false;
     var CoinTexture : Texture;
      public var Money :int=0;
     var skin : GUISkin;
     var AddButton = false;
     //Items:
     //to add more items just copy this variable and add the item name;
     
     var Item : Texture;
     var Item2 :Texture;
     var Item3 :Texture;
     
     //code----------------------------------------
     function Start () {
     Money = PlayerPrefs.GetInt("Money", 0);
     }
     function Update () {
     PlayerPrefs.SetInt ("Money", Money);
     if(Money <= 0){
     Money = 0;
     }
     }
     
     
     function OnGUI(){
     GUI.skin = skin;
     if(ShowShop ==true){
     //money{********************-------------------------------------------------------------**************************
     GUI.Button(Rect(Screen.width/60,Screen.height/60  ,50,50), CoinTexture);
     GUI.Button(Rect(Screen.width/60+50,Screen.height/60  ,70,50), ""+Money);
     if(AddButton ==true){
     if(GUI.Button(Rect(Screen.width/60+120,Screen.height/60  ,70,50), "Add")){
     Money += 100;
     }
     }
     //money}***********************-------------------------------------------------------------------*****************************
     
     //Items(Shop){
     if(GUI.Button(Rect(Screen.width/2,Screen.height/2,150,150), Item)){
     if(Money >= 200){
     Money -= 200;
     }else{
     Money -=0;
     }
     }
     GUI.Button(Rect(Screen.width/2+150,Screen.height/2,150,150), "Buy: 200");
     
     if(GUI.Button(Rect(Screen.width/2,Screen.height/2- -150,150,150), Item2)){
     if(Money >= 150){
     Money -= 150;
 
 }else{
 Money -=0;
 }
 }
 GUI.Button(Rect(Screen.width/2+150,Screen.height/2- -150,150,150), "Buy: 150");
 
 if(GUI.Button(Rect(Screen.width/2,Screen.height/2- 150,150,150), Item3)){
 if(Money >= 500){
 Money -= 500;
 }else{
 Money -=0;
 }
 }
 GUI.Button(Rect(Screen.width/2+150,Screen.height/2- 150,150,150), "Buy: 500");
 //Items(Shop)}
 
 
 }
 }//OnGUI End////////////////////////////////////

Comment

People who like this

0 Show 0
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

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

37 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

Related Questions

I really need help with this message 0 Answers

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Error BCE0051 with script JS 1 Answer

Getting error on lap counter script JS 0 Answers

Random Chance NullReferenceException: 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