- Home /
Ontriggerenter button prompt + material change?
Hey, I know this sort of question has been asked countless times before, but I'm still hoping for some help, if anyone can be of service.
In my scene, I have a piece of paper sitting on a desk. When I walk up to it, I want a GUI message to appear, telling me to "Press 'Action'" which I have bound to the E key. Upon pressing the button, the texture on the paper is to change, giving the effect of it having been drawn on. I have 7 different drawings and one blank paper material. Here's my code so far.
var hasCollided : boolean = false;
var labelText : String = "";
public var textureList : Texture[];
public var objectList : GameObject[];
public var textureNumber : int;
var coolDown : int = 1;
var lastClickTime : float;
function OnGUI()
{
if (hasCollided ==true)
{
GUI.Box(Rect(140,Screen.height-50,Screen.width-300,120),(labelText));
}
}
function OnTriggerEnter(c:Collider)
{
if(c.gameObject.tag =="Player")
{
hasCollided = true;
labelText = "Paper - Press 'Action'";
}
}
function Update ()
{
if (Input.GetButtonDown("Action"))
{
if(lastClickTime + coolDown < Time.time)
{
lastClickTime = Time.time;
textureNumber ++;
if (textureNumber > textureList.length - 1)
{
textureNumber = 0;
}
for (var i = 0; i < objectList.length; i++)
{
objectList[i].renderer.material.mainTexture = textureList[textureNumber];
}
}
}
}
function OnTriggerExit( other : Collider ){
hasCollided = false;
}
My problem is pressing the action button won't do anything, even though it is set up. The button prompt appears/disappears fine, however. Can someone please revise my code?
Your answer
![](https://koobas.hobune.stream/wayback/20220613140929im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Won't Enter GetButton Statement 1 Answer
Trying to make it so if I'm toucing something and have a button down it does something 1 Answer
about OnTriggerEnter 1 Answer
OnTriggerEnter GUI 1 Answer