'Image' does not contain a definition for 'texture' and no accessible extension method

Viewed 28

"Image" does not contain a definition for "texture" and no accessible extension method "texture" accepting a first argument of type "Image" could be found (are you missing a using directive or an assembly reference?

using UnityEngine;
using UnityEngine.UI;

public class CFX_Demo_GTToggle : MonoBehaviour
{
    public Texture Normal;

    public Texture Hover;

    public Color NormalColor = new Color32(128, 128, 128, 128);

    public Color DisabledColor = new Color32(128, 128, 128, 48);

    public bool State = true;

    public string Callback;

    public GameObject Receiver;

    private Rect CollisionRect;

    private bool Over;

    private Image Label;

    private void Awake()
    {
        CollisionRect = GetComponent<Rect>().GetScreenRect(Camera.main);
        Label = GetComponentInChildren<Text>();
        UpdateTexture();
    }

    private void Update()
    {
        if (CollisionRect.Contains(Input.mousePosition))
        {
            Over = true;
            if (Input.GetMouseButtonDown(0))
            {
                OnClick();
            }
        }
        else
        {
            Over = false;
            GetComponent< Image>().color = NormalColor;
        }
        UpdateTexture();
    }

    private void OnClick()
    {
        State = !State;
        Receiver.SendMessage(Callback);
    }

    private void UpdateTexture()
    {
        Color color = (!State) ? DisabledColor : NormalColor;
        if (Over)
        {
            GetComponent<Image>().texture = Hover;
        }
        else
        {
            GetComponent<Image>().texture = Normal;
        }
        GetComponent<Image>().color = color;
        if (Label != null)
        {
            Label.color = color * 1.75f;
        }
    }
}
0 Answers
Related