Been trying to get this script together for things like interactive signs.
What I basically need is a trigger area that will detect when the player (a first person controller) enters and then display a prompt (“Press x to read”). When the player hits that key a scrollview then appears that they can read through and then when they’re done press another key to get rid of it. Finally, the prompt needs to disappear after the player leaves the trigger area.
So far I’ve gotten a text area to appear on entering the trigger and that’s it so any help would be appreciated.
Haven’t tested this so if it doesn’t work thats why and if you need it in javascript it can be easily converted to javascript.
using UnityEngine;
using System.Collections;
public class TextTrigger : MonoBehaviour {
public bool isInTrigger = false;
public bool activateScroll = false;
public Vector2 scrollPosition = Vector2.zero;
void OnTriggerEnter(){
isInTrigger = true;
}
void OnTriggerExit(){
isInTrigger = false;
}
void OnGUI(){
if(isInTrigger){
GUI.Label(new Rect(10,10,100,50),"Press X to read");
}
if(activateScroll){
scrollPosition = GUI.BeginScrollView(new Rect(10, 300, 100, 100),
scrollPosition,new Rect(0, 0, 220, 200));
//CHANGE THIS FOR TEXT AREA
GUI.Button(new Rect(0, 0, 100, 20), "Button");
GUI.Button(new Rect(120, 0, 100, 20), "Button");
GUI.Button(new Rect(0, 180, 100, 20), "Button");
GUI.Button(new Rect(120, 180, 100, 20), "Button");
GUILayout.EndScrollView;
}
}
void Update(){
if(isInTrigger&&Input.GetKeyDown(KeyCode.E)){
activateScroll = true;
}
if(Input.GetKeyDown(KeyCode.E)&&activateScroll){
activateScroll = false;
}
}
}