Hello, I am trying to make it so that when I click my mouse button while over a trigger, that the game objects tag changes. For example if my mouse is over a red square and I click it, I want it to change the tag to safe using a trigger. How do I make my mouse button a trigger in this case? Currently I have a script where if the ball rolls over the item it changes the tag Code (csharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Hurtful : MonoBehaviour { private void OnTriggerEnter2D(Collider2D collision) { gameObject.tag = "Safe"; } } But that's just any and all objects with a trigger. I am planning it so that if my mouse clicks the object, it changes the tag, and the ball continues rolling but if I don't change it the ball triggers another scene. So I need to know two things: How do I make it so when my mouse it over a trigger and I click, it triggers whatever is OnTriggerEnter2D, and how would I make it so that if my gameObject touches a tag that isnt Safe or untagged it loads a scene from scenemanager?
The OnTrigger family of methods is called from the physics engine, not from the mouse. Are you perhaps looking or something like OverlapPoint()? https://docs.unity3d.com/ScriptReference/Physics2D.OverlapPoint.html or perhaps: https://docs.unity3d.com/ScriptReference/Collider2D.OverlapPoint.html If that's not it, start with some tutorials for what you're trying to accomplish. No sense in one of us trying to guess and typing a bunch of text in this box when it's already waiting for you on Youtube.
you can use OnMouseDown() https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html or OnMouseEnter()