- Home /
The question is answered, right answer was accepted
Property guiTexture has been deprecated . Use GetComponent()
using UnityEngine; using System.Collections;
public class ButtonOK : MonoBehaviour {
public string loadSceneName; //Next load scene name
public Texture2D buttonOkNormal; //Texture button normal
public Texture2D buttonOkDown; //Texture button down
public Entername enterNameScript; //script entername
public SelectCharacter selectCharacterScript; //script select character
public AudioClip sfxButton; //sound effect when click this button
void OnMouseUp()
{
//change texture to "normal"
this.gameObject.guiTexture.texture = buttonOkNormal;
//Save select character and name
PlayerPrefs.SetString("pName",enterNameScript.defaultName);
PlayerPrefs.SetInt("pSelect",selectCharacterScript.indexHero);
SpawnPointHero.enableLoadData = true;
//Load next scene
Invoke("LoadScene",0.1f);
}
void OnMouseDown()
{
//change texture to "down"
this.gameObject.guiTexture.texture = buttonOkDown;
//Play sfx
if(sfxButton != null)
AudioSource.PlayClipAtPoint(sfxButton,transform.position);
}
void LoadScene()
{
Application.LoadLevel(loadSceneName);;
}
}
Answer by meat5000 · Apr 20, 2016 at 10:50 AM
The error is telling you that you can not use .guiTexture to refer to that object any more. The shortcut has been removed and now you must access it using GetComponent, just like any other component.
So it'll be something like this :
gameObject.GetComponent<GUITexture>().texture
You'll get an error unless you do something with it though.
One way or another you need make it equal something.
1) Store it in a variable
GUITexture myGT = gameObject.GetComponent<GUITexture>();
myGT.texture = someTexture2D;
2) Use it instantaneously
gameObject.GetComponent<GUITexture>().texture = someTexture2D;
I did that but after that it says that "the left hand of an assignment must be a variable property or indexer"
gameObject.GetComponent().texture it is already equal with buttonOkNormal and the other one with buttonOkDown
public class ButtonO$$anonymous$$ : $$anonymous$$onoBehaviour {
public string loadSceneName; //Next load scene name
public Texture2D buttonOkNormal; //Texture button normal
public Texture2D buttonOkDown; //Texture button down
public Entername enterNameScript; //script entername
public SelectCharacter selectCharacterScript; //script select character
public AudioClip sfxButton; //sound effect when click this button
void On$$anonymous$$ouseUp()
{
//change texture to "normal"
this.gameObject.GetComponent<GUITexture>().texture = buttonOkNormal;
//Save select character and name
PlayerPrefs.SetString("pName", enterNameScript.defaultName);
PlayerPrefs.SetInt("pSelect", selectCharacterScript.indexHero);
SpawnPointHero.enableLoadData = true;
//Load next scene
Invoke("LoadScene", 0.1f);
}
void On$$anonymous$$ouseDown()
{
//change texture to "down"
this.gameObject.GetComponent<GUITexture>().texture = buttonOkDown;
//Play sfx
if (sfxButton != null)
AudioSource.PlayClipAtPoint(sfxButton,transform.position);
}
void LoadScene()
{
Application.LoadLevel(loadSceneName);;
}
}