Hello,
I had my previous question closed for “Duplicate” reasons. When I wasn’t asking about “HOW TO MAKE A GUI APPEAR” I wanted help on how to recheck the raycast, as I keep getting errors when I tried adding the line: “if(Physics.Raycast(trasnform…)”
I have some code to check if the player is within a certain distance from an object (essentially a door) but want to add a GUI label popup to prompt the player when wanting to open the door. I’m not sure what I should use for the ‘if’ statement to check whether it’s within range. As you can see by the commented “if(RaycastHit Hit = true))”
using UnityEngine;
using System.Collections;
public class New_Level_Door : MonoBehaviour {
void Update()
{
if(Input.GetKeyDown(KeyCode.E) && CheckForDoor())
{
Application.LoadLevel("MainMenu");
}
}
bool CheckForDoor()
{
RaycastHit hit;
if(Physics.Raycast(transform.position, transform.forward, out hit, 2))
{
Debug.LogWarning("Press E to open the door");
if(hit.transform.tag == "LevelEnd")
{
return true;
}
}
return false;
}
void OnGUI()
{
//if(RaycastHit hit = true))
{
GUI.Label (new Rect(5,0,100,20 ),"Press 'E' to open the door!");
}
}
}
Thanks for your time!