I tried fixing "Using GUiTexture has been removed, use UI.Image instead" But it wont work
Help!! I have been trying to fix this for hours now and can't find out how to do it
The original code was this
using UnityEngine; using UnityEngine.SceneManagement;
public class LoadGame : MonoBehaviour {
public Texture2D playNormal;
public Texture2D playHover;
void OnMouseEnter(){
GetComponent<GUITexture>().texture = playHover;
}
void OnMouseExit(){
GetComponent<GUITexture>().texture = playNormal;
}
void OnMouseDown()
{
//Nilupul
//SaveGame.Instance.Load();
SaveGame.Instance.IsSaveGame = true;
SceneManager.LoadScene ("Test");
}
// Use this for initialization
void Start () {
}
}
I tried doing what it told me "Use UI.Image instead" And still didnt work, it just said "the type or namespace "UI could not be found (are you missing a using directive or an assembly reference?"
This is the code after I tried fixing it
using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class LoadGame : MonoBehaviour {
public Texture2D playNormal;
public Texture2D playHover;
void OnMouseEnter(){
GetComponent<UI.Image>().texture = playHover;
}
void OnMouseExit(){
GetComponent<UI.Image>().texture = playNormal;
}
void OnMouseDown()
{
//Nilupul
//SaveGame.Instance.Load();
SaveGame.Instance.IsSaveGame = true;
SceneManager.LoadScene ("Test");
}
// Use this for initialization
void Start () {
}
} ,This is the code
using UnityEngine; using UnityEngine.SceneManagement;
public class LoadGame : MonoBehaviour {
public Texture2D playNormal;
public Texture2D playHover;
void OnMouseEnter(){
GetComponent<GUITexture>().texture = playHover;
}
void OnMouseExit(){
GetComponent<GUITexture>().texture = playNormal;
}
void OnMouseDown()
{
//Nilupul
//SaveGame.Instance.Load();
SaveGame.Instance.IsSaveGame = true;
SceneManager.LoadScene ("Test");
}
// Use this for initialization
void Start () {
}
}
This is what I did that it told me to, but still didn't work, pls help
using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class LoadGame : MonoBehaviour {
public Texture2D playNormal;
public Texture2D playHover;
void OnMouseEnter(){
GetComponent<UI.Image>().texture = playHover;
}
void OnMouseExit(){
GetComponent<UI.Image>().texture = playNormal;
}
void OnMouseDown()
{
//Nilupul
//SaveGame.Instance.Load();
SaveGame.Instance.IsSaveGame = true;
SceneManager.LoadScene ("Test");
}
// Use this for initialization
void Start () {
}
}
All it said after doing what I was told was "The type or namespace name UI could not be found (are you missing a using directive or an assembly reference?)"
Answer by KoenigX3 · Apr 18, 2021 at 09:08 AM
You only need
GetComponent<Image>()
Also, use GetComponent on Start, set up a reference, and use that later.
// Use this on Start
Image img = GetComponent<Image>();
// Use this whenever you want to access the Image component
img.texture = playHover;
img.texture = playNormal;
Keep in mind that it works only if your GameObject has an Image component on it.
Thank you! I will try this out, hopefully it works
Thank you so much! It worked!! Much appreciated