Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mr_Love_Gloves

Pages: [1]
1
NGUI 3 Support / Re: UIToggle = null???? (Aren Mook please help)
« on: July 11, 2014, 05:45:41 AM »
Thank you that advice will help me, turns out the problem was every time the scene reloaded the toggle component disapeared from the variable so i just moved the script to the actual toggle and now everything works :D

2
NGUI 3 Support / UIToggle = null???? (Solved)
« on: July 10, 2014, 07:01:17 AM »
With my code I am trying to have a toggle button that mutes and plays sound, it works when it first loads up, but when I carry on through the game and end back at this start screen Toggle is = Null and the toggle does not mute the audio or work. I have no idea why its = null the second time round. Any help would be great  :D

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class SoundButtionGUI : MonoBehaviour {
  5.        
  6.  
  7.         public UIToggle toggle;
  8.        
  9.  
  10.         void Awake () {
  11.                 if (PlayerPrefs.GetInt ("SoundMute") == 1) {
  12.                         toggle.value = true;
  13.                 } else {
  14.                         toggle.value = false;
  15.                 }      
  16.  
  17.         }
  18.  
  19.         void Update () {       
  20.                 if (Application.loadedLevel == 0) {
  21.                         if(toggle == null){
  22.                                 Debug.Log ("Toggle = Null");
  23.                         }
  24.  
  25.                                 if(toggle.value == true && toggle != null){
  26.                                 PlayerPrefs.SetInt("SoundMute", 1);
  27.                                 Invoke("audioOff", 0.01f);
  28.                         } else{
  29.                                 Invoke("audioOn", 0.01f);
  30.                                 PlayerPrefs.SetInt("SoundMute", 0);
  31.                         }
  32.                 }
  33.         }
  34.  
  35.         void audioOn(){
  36.                 audio.volume = 1;
  37.         }
  38.        
  39.         void audioOff(){
  40.                 audio.volume = 0;
  41.         }
  42. }
  43.  

3
This is the code
  1.         public Texture2D icon;
  2.         public Texture2D iconClicked;
  3.         public GUISkin toggleSkin;
  4.        
  5.         private bool muteToggle = false;
  6.         private bool toggleImg = false;
  7.         public UIToggle toggle;
  8.        
  9.         // Use this for initialization
  10.         void Awake () {
  11.                 if (PlayerPrefs.GetInt ("SoundMute") == 1) {
  12.                         toggle.value = true;
  13.                 } else {
  14.                         toggle.value = false;
  15.                 }
  16.         }
  17.         // Update is called once per frame
  18.         void Update () {
  19.                 if (Application.loadedLevel == 0) {
  20.  
  21.                                 if(toggle != null && toggle.value == true ){
  22.                                 PlayerPrefs.SetInt("SoundMute", 1);
  23.                                 Invoke("audioOff", 0.01f);
  24.                         } else{
  25.                                 Invoke("audioOn", 0.01f);
  26.                                 PlayerPrefs.SetInt("SoundMute", 0);
  27.                         }
  28.                 }
  29.         }
  30.  
  31.         void audioOn(){
  32.                 audio.volume = 1;
  33.         }
  34.        
  35.         void audioOff(){
  36.                 audio.volume = 0;
  37.         }

4
if(toggle != null && toggle.value == true )
I changed it to that which did stop the error, but now when i go through the levels and get back to the start screen the toggle button does not work as toggle is returning null

5
Thanks for the quick reply, I found that out I just dont know what would be a fix to that? any ideas? :P

6
0
I cant deal with these errors >:[ any help on this one??

Error: NullReferenceException: Object reference not set to an instance of an object SoundButtionGUI.Update () (at Assets/SoundButtionGUI.cs:27)

Im getting the errors with : if(toggle.value == true)
>> this is the variable: public UIToggle toggle;

  1. if (Application.loadedLevel == 0) {
  2.             if(toggle.value == true){
  3.                 PlayerPrefs.SetInt("SoundMute", 1);
  4.                 Invoke("audioOff", 0.01f);
  5.             } else{
  6.                 Invoke("audioOn", 0.01f);
  7.                 PlayerPrefs.SetInt("SoundMute", 0);
  8.             }
  9.         }

Ive tried this:
if(toggle.value == true && toggle != null && toggle.value != null && toggle.value != false)
Also: if(toggle == true) which stops the error but the code does not work because toggle sometimes returns null
Any help would be great


Any help would be great, I have had loads of these errors and have had to ask on here for every single one -_-

Pages: [1]