I have an object in Unity (cube) which its material changes with mouse click. I want to show information about each material in a UI text. So, the information needs to be changed. I have written the following script and it works when I assign it to a UI button. It means that my text is changed when I click on the button. But when I assign it to the cube, my text isn’t changed by mouse click. I would appreciate it if you could answer my question.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CubeText : MonoBehaviour
{
public Text changingText;
private int i = 0;
public void textChange()
{
{
switch (i)
{
case 0:
changingText.text = "Parket...";
break;
case 1:
changingText.text = "Kashi...!";
break;
case 2:
changingText.text = "Seramic...!";
break;
}
i++;
i = i % 3;
}
}
}