Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by m-y · Sep 10, 2014 at 03:55 AM · c#androidtexture

null texture passed to GUI.DrawTexture

aha a problem i don't understand i have this script to make player choose between 50 levels in the game but it is give me this error

null texture passed to GUI.DrawTexture UnityEngine.GUI:DrawTexture(Rect, Texture) MainMenuScript:drawLocks() (at Assets/Assets/Assets/Scripts/MainMenuScript.cs:101) MainMenuScript:OnGUI() (at Assets/Assets/Assets/Scripts/MainMenuScript.cs:32)

that is the whole script what is the error ?

 using UnityEngine;
 using System.Collections;
 
 public class MainMenuScript : MonoBehaviour 
 {public AudioClip sound  ; 
     public GUISkin GameSkin;
     public GUIStyle buttons;
     public GUIStyle buttonsOnHover;
     public bool levelChooced = false;
     public int lastLevelComplete;
     public Texture lockPic;
     public Texture lockPic2;
     int currentChapter = 1;
     bool selectLevel = false;
     public Texture2D newgame ; 
     public Texture2D selectlevel ; 
     public Texture2D Back ; 
     public Texture2D chapter1 ; 
     
     void Awake(){
         lastLevelComplete = PlayerPrefs.GetInt ("lastLevelComplete") ;
     }
     
     void OnGUI()
     {
         GUI.Label( new Rect ( 10,10,20,20),""+lastLevelComplete) ; 
     
         GUI.depth = -1;
         
         if (selectLevel) {
             LevelSelectMenu();
             drawLocks ();    
         }else{
             if (GUI.Button (new Rect (Screen.width / 2 - 125, Screen.height / 2 - 50, 200, 200), new GUIContent (newgame, "newgame"), buttons)){
                 audio.PlayOneShot(sound) ; 
                 
                 Application.LoadLevel("1");
             }
             if (GUI.Button (new Rect (Screen.width / 2 +125, Screen.height / 2 - 25, 100, 100), new GUIContent (selectlevel,"Select Level"), buttons)) {
                 audio.PlayOneShot(sound) ; 
                 selectLevel = true;
             }
             if (GUI.Button (new Rect (Screen.width / 2 - 275, Screen.height / 2 - 25, 100, 100), new GUIContent (Back,"Back"), buttons))
             {    
                 audio.PlayOneShot(sound) ; 
                 Application.LoadLevel ("Main Menu");
                 Destroy(GameObject.Find("Music")) ;
                 PlayerPrefs.GetFloat ("volumelevels") ;
             }
         }
     }
     
     
     void LevelSelectMenu()
     {
         if(currentChapter == 1){
             chapter1_wide();
             if(GUI.Button (new Rect (Screen.width * 0.71f, Screen.height * 0.8f, Screen.width*1f, Screen.height*1f), new GUIContent("  >","next"),buttons))
                 currentChapter++;
         }
         else if(currentChapter == 2){
             chapter2();
             if(GUI.Button (new Rect (Screen.width * 0.19f, Screen.height * 0.8f, Screen.width*0.3f, Screen.height*0.03f), new GUIContent("<","back"),buttons))
                 currentChapter--;
             if(GUI.Button (new Rect (Screen.width * 0.71f, Screen.height * 0.8f, Screen.width*0.3f, Screen.height*0.3f), new GUIContent("  >","next"),buttons))
                 currentChapter++;
         }
         else if(currentChapter == 3){
             if(GUI.Button (new Rect (Screen.width * 0.19f, Screen.height * 0.8f, Screen.width*0.1f, Screen.height*0.05f), new GUIContent("<","back"),buttons))
                 currentChapter--;
             if(GUI.Button (new Rect (Screen.width * 0.71f, Screen.height * 0.8f, Screen.width*0.1f, Screen.height*0.05f), new GUIContent("  >","next"),buttons))
                 currentChapter++;
             chapter3();
         }
         else if(currentChapter == 4){
             if(GUI.Button (new Rect (Screen.width * 0.19f, Screen.height * 0.8f, Screen.width*0.1f, Screen.height*0.05f), new GUIContent("<","back"),buttons))
                 currentChapter--;
             if(GUI.Button (new Rect (Screen.width * 0.71f, Screen.height * 0.8f, Screen.width*0.1f, Screen.height*0.05f), new GUIContent("  >","next"),buttons))
                 currentChapter++;
             chapter4();
         }
         else if(currentChapter == 5){
             if(GUI.Button (new Rect (Screen.width * 0.19f, Screen.height * 0.8f, Screen.width*0.1f, Screen.height*0.05f), new GUIContent("<","back"),buttons))
                 currentChapter--;
             chapter5();
         }    
         
         if (GUI.Button (new Rect (Screen.width * 0.03f, Screen.height * 0.87f, Screen.width * 0.18f, Screen.height * 0.09f), new GUIContent ("Back", "minu"), buttons))
             selectLevel = false;
         
         
         }
     
     
     void drawLocks(){
         int w = Screen.width;
         int h = Screen.height;
         if((((currentChapter-1)*10)) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.11f*w, 0.18f*h,64,64),lockPic);//1
         else
             GUI.DrawTexture(new Rect(0.11f*w, 0.18f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+1) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.31f*w, 0.18f*h,64,64),lockPic);//2
         else
             GUI.DrawTexture(new Rect(0.31f*w, 0.18f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+2) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.51f*w, 0.18f*h,64,64),lockPic);//3
         else
             GUI.DrawTexture(new Rect(0.51f*w, 0.18f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+3) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.71f*w, 0.18f*h,64,64),lockPic);//4
         else
             GUI.DrawTexture(new Rect(0.71f*w, 0.18f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+4) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.11f*w, 0.47f*h,64,64),lockPic);//5
         else
             GUI.DrawTexture(new Rect(0.11f*w, 0.47f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+5) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.31f*w, 0.47f*h,64,64),lockPic);//6
         else
             GUI.DrawTexture(new Rect(0.31f*w, 0.47f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+6) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.51f*w, 0.47f*h,64,64),lockPic);//7
         else
             GUI.DrawTexture(new Rect(0.51f*w, 0.47f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+7) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.71f*w, 0.47f*h,64,64),lockPic);//8
         else
             GUI.DrawTexture(new Rect(0.71f*w, 0.47f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+8) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.31f*w, 0.75f*h,64,64),lockPic);//9
         else
             GUI.DrawTexture(new Rect(0.31f*w, 0.75f*h,64,64),lockPic2);
         
         if((((currentChapter-1)*10)+9) > lastLevelComplete)
             GUI.DrawTexture(new Rect(0.51f*w, 0.75f*h,64,64),lockPic);//10
         else
             GUI.DrawTexture(new Rect(0.51f*w, 0.75f*h,64,64),lockPic2);
     }
     
     void chapter1_wide(){
         int w = Screen.width;
         int h = Screen.height;
         if(GUI.Button(new Rect(0.11f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 01"))
         {
             Application.LoadLevel("1");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 02")&& lastLevelComplete>=2)
         {
             Application.LoadLevel("2");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 03")&& lastLevelComplete>=3)
         {
             Application.LoadLevel("3");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 04")&& lastLevelComplete>=4)
         {
             Application.LoadLevel("4");
         }
         if(GUI.Button(new Rect(0.11f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 05")&& lastLevelComplete>=5)
         {
             Application.LoadLevel("5");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 06")&& lastLevelComplete>=6)
         {
             Application.LoadLevel("6");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 700")&& lastLevelComplete>=7)
         {
             Application.LoadLevel("7");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 08")&& lastLevelComplete>=8)
         {
             Application.LoadLevel("8");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 09")&& lastLevelComplete>=9)
         {
             Application.LoadLevel("9");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 10")&& lastLevelComplete>=10)
         {
             Application.LoadLevel("10");
         }
     }
     
     void chapter2(){
         int w = Screen.width;
         int h = Screen.height;
         if(GUI.Button(new Rect(0.11f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 11")&& lastLevelComplete>=11)
         {
             Application.LoadLevel("11");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 12")&& lastLevelComplete>=12)
         {
             Application.LoadLevel("12");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 13")&& lastLevelComplete>=13)
         {
             Application.LoadLevel("13");
         }
         
         if(GUI.Button(new Rect(0.71f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 14")&& lastLevelComplete>=14)
         {
             Application.LoadLevel("14");
         }
         
         if(GUI.Button(new Rect(0.11f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 15")&& lastLevelComplete>=15)
         {
             Application.LoadLevel("15");
         }
         
         if(GUI.Button(new Rect(0.31f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 16")&& lastLevelComplete>=16)
         {
             Application.LoadLevel("16");
         }
         
         if(GUI.Button(new Rect(0.51f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 17")&& lastLevelComplete>=17)
         {
             Application.LoadLevel("17");
         }
         
         if(GUI.Button(new Rect(0.71f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 18")&& lastLevelComplete>=18)
         {
             Application.LoadLevel("18");
         }
         
         if(GUI.Button(new Rect(0.31f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 19")&& lastLevelComplete>=19)
         {
             Application.LoadLevel("19");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 20")&& lastLevelComplete>=20)
         {
             Application.LoadLevel("20");
         }
     }
     
     void chapter3(){
         int w = Screen.width;
         int h = Screen.height;
         if(GUI.Button(new Rect(0.11f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 21")&& lastLevelComplete>=21)
         {
             Application.LoadLevel("21");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 22")&& lastLevelComplete>=22)
         {
             Application.LoadLevel("22");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 23")&& lastLevelComplete>=23)
         {
             Application.LoadLevel("23");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 24")&& lastLevelComplete>=24)
         {
             Application.LoadLevel("24");
         }
         if(GUI.Button(new Rect(0.11f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 25")&& lastLevelComplete>=25)
         {
             Application.LoadLevel("25");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 26")&& lastLevelComplete>=26)
         {
             Application.LoadLevel("26");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 27")&& lastLevelComplete>=27)
         {
             Application.LoadLevel("27");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 28")&& lastLevelComplete>=28)
         {
             Application.LoadLevel("28");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 29")&& lastLevelComplete>=29)
         {
             Application.LoadLevel("29");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 30")&& lastLevelComplete>=30)
         {
             Application.LoadLevel("30");
         }
     }
     
     void chapter4(){
         int w = Screen.width;
         int h = Screen.height;
         if(GUI.Button(new Rect(0.11f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 31")&& lastLevelComplete>=31)
         {
             Application.LoadLevel("31");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 32")&& lastLevelComplete>=32)
         {
             Application.LoadLevel("32");
         }
         
         if(GUI.Button(new Rect(0.51f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 33")&& lastLevelComplete>=33)
         {
             Application.LoadLevel("33");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 34")&& lastLevelComplete>=34)
         {
             Application.LoadLevel("34");
         }
         if(GUI.Button(new Rect(0.11f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 35")&& lastLevelComplete>=35)
         {
             Application.LoadLevel("35");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 36")&& lastLevelComplete>=36)
         {
             Application.LoadLevel("36");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 37")&& lastLevelComplete>=37)
         {
             Application.LoadLevel("37");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 38")&& lastLevelComplete>=38)
         {
             Application.LoadLevel("38");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 39")&& lastLevelComplete>=39)
         {
             Application.LoadLevel("39");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 40")&& lastLevelComplete>=40)
         {
             Application.LoadLevel("40");
         }
     }
     
     void chapter5(){
         int w = Screen.width;
         int h = Screen.height;
         if(GUI.Button(new Rect(0.11f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 41")&& lastLevelComplete>=41)
         {
             Application.LoadLevel("41");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 42")&& lastLevelComplete>=42)
         {
             Application.LoadLevel("42");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 43")&& lastLevelComplete>=43)
         {
             Application.LoadLevel("43");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.08f*h, 0.18f*w , 0.26f*h ), "Level 44")&& lastLevelComplete>=44)
         {
             Application.LoadLevel("44");
         }
         if(GUI.Button(new Rect(0.11f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 45")&& lastLevelComplete>=45)
         {
             Application.LoadLevel("45");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 46")&& lastLevelComplete>=46)
         {
             Application.LoadLevel("46");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 47")&& lastLevelComplete>=47)
         {
             Application.LoadLevel("47");
         }
         if(GUI.Button(new Rect(0.71f*w, 0.37f*h, 0.18f*w , 0.26f*h ), "Level 48")&& lastLevelComplete>=48)
         {
             Application.LoadLevel("48");
         }
         if(GUI.Button(new Rect(0.31f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 49")&& lastLevelComplete>=49)
         {
             Application.LoadLevel("49");
         }
         if(GUI.Button(new Rect(0.51f*w, 0.66f*h, 0.18f*w , 0.26f*h ), "Level 50")&& lastLevelComplete>=50)
         {
             Application.LoadLevel("50");
         }
     }
 }
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 zharik86 · Sep 10, 2014 at 06:00 AM 0
Share

Check in Inspector yputr object to witch the script attached. Check all public variable. Also check that the lockPic2 variable had a texture.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

how to make high quality textures with low size of downlaod 1 Answer

what is Wrong in my Script ( c#) ? 1 Answer

Multiple Tiled GPU warning: RenderTexture color surface errors? 0 Answers

C# cannot convert 'char' expression to type 'UnityEngine.Texture' 1 Answer

C# combining Two Textures 3 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