Hello, for my VR application I need to change material of the image component of the UI button I used.
I wrote a code to do that but when trying to add it to the gameobject, Unity gives me “script class cannot be found” error.
This script will be executed through an OnClick function in the button component of the same gameobject.
Can anyone help me?
I’m relatively new to Unity, I’m sorry for any obvious errors.
using UnityEngine;
using System.Collections;
using UnityEngine.UIElements; // dont know if I have to use this or the next one or neither or both
using UnityEngine.UI;
public class ChangeMaterial : MonoBehaviour
{
public GameObject myObject;
private Color startmaterial;
int counter=0;
void start ()
{
}
public void materialf()
{
counter++;
if (counter%2==1)
{
startmaterial = myObject.GetComponent<Image>().material.color = Color.green;
}
if (counter%2==0)
{
myObject.GetComponent<Image>().material.color = startmaterial;
}
}
}