I want to open an UI element when raycast hits a certain object. I’ve gotten to a point where it works if the raycast hits any object, but not from a certain object. I’ve tried it with tags, but couldn’t get it to work either.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnClickDestroy : MonoBehaviour
{
public GameObject Trader;
public void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, 2))
{
//Here it stops working, this line doesn't do anything
if (gameObject == Trader)
{
Destroy(Trader);
}
}
}
}
}