Can someone please tell me what I’m doing wrong. I’m trying to have whenever the player looks at an item with the tag “pickup” be able to be recognized by the raycast and show a text saying “press e to pickup”.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Raycast : MonoBehaviour {
public GameObject pickUp;
private bool canHover = false;
void update ()
{
var fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if (Physics.Raycast(transform.position, fwd, hit))
{
if (hit.distance <= 5.0f && hit.collider.gameObject.tag == "pickup")
{
canHover = true;
if(Input.GetKeyDown("e"))
{
Destroy(pickUp);
}
}
else
{
canHover = false;
}
}
}
void OnGUI()
{
if (canHover == true)
{
GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 100, 150, 20), "Press E to Pick Up!");
}
}
}