I've been recently working on a videogame, and I'm trying to make a script that will destroy the game object it is applied to whenever the right mouse button is clicked on it. It doesn't function at all and I don't receive any error messages in the Console. Here is all my code:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class RightClick: MonoBehaviour, IPointerClickHandler
{
// Initiates whenever the pointer is clicked
public void OnPointerClick(PointerEventData eventData)
{
// Destroys item from players inventory when pressed
if (eventData.pointerId == -2)
{
// Removes object from inventory
Object.Destroy(this.gameObject);
}
}
}
I have searched for hours on this topic and have only found extremely outdated sources, please help me!
UnityEngine.EventSystems
namespace to work. \$\endgroup\$