Press E to Read note
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
Answer by DoubleIsLoveDoubleIsLife · Jun 18, 2015 at 09:01 AM
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 \n.
thanks :D with a bit of tweaking i can make this work well no offence but its rather wonky at the moment, but again i couldn't even begin to work on this script thanks :D
Your answer
Follow this Question
Related Questions
Failed to Initialize 3D Graphics? 10 Answers
Device.present, Overhead, camera.render slowing the fps 0 Answers
Static Collider.Move warning is still in place: should I add Rigidbody or not? (Unity 5.3.3f1) 0 Answers
Optimize mobile game with lot of Rigidbodies (Collisions) 0 Answers
Game got slow after updating to 2017.3 0 Answers