Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Help with JS script

$
0
0
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////////////////////////////////////

Viewing all articles
Browse latest Browse all 7934

Trending Articles