- Home /
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
Check in Inspector yputr object to witch the script attached. Check all public variable. Also check that the lockPic2 variable had a texture.