i am new to programming i am currently trying to develop a horror game but i haven’t the faintest idea how to have an object say “press e to read note” when mouse is hovering over object, i am using C# if anyone knows please let me know
using UnityEngine;
using System.Collections;
public class PressEToRead : MonoBehaviour {
public GameObject Player;
public float minDist = 5f;
public string text = "Spooky skeletons";
float dist;
bool reading = false;
void Update () {
dist = Vector3.Distance(Player.gameObject.transform.position, gameObject.transform.position);
if (dist <= minDist) {
if(Input.GetKeyDown(KeyCode.E)) {
if(reading) {
reading = false;
}
else {
reading = true;
}
}
}
else {
reading = false;
}
}
void OnGUI() {
if(reading) {
GUI.TextArea(new Rect(Screen.height/2, Screen.width/2, 500, 500), text);
}
else if(dist <= minDist) {
GUI.TextArea(new Rect(Screen.height/2, Screen.width/2, 500, 500), "Press 'E' to read.");
}
}
}
Save as ‘PressEToRead.C#’, add to note object, assign player, and add the text. You can enter new line with
.
I have no idea. Looks cool tho.