Hello, i’m doing a script that makes the objects act upon mouse movements. Basically, objecs have to react to mouse passing over them, clicking on them or dragging on them.
For that i use the so convenient OnMouseEnter, OnMouseExit, OnMouseDown, OnMouseUp and OnMouseDrag. The problem i’m having is trying to assign different scripts to each of a mouse’s button. Here’s what i have so far :
public class Act : MonoBehaviour
{
//Testing with one event till getting it right
//The list containing the scripts to use (index indicates the mouse button)
public MonoBehaviour[] onMouseDown = null;
//Used to activate OnGui part
private bool onMDown = false;
void OnMouseDown()
{
onMDown = true;
}
//Using OnGUI to get the mouse button pressed with Event
void OnGUI()
{
if (onMDown)
{
int i = 0;
//Don't do anything if mouse has more buttons than we predicted
if (onMouseDown != null && onMouseDown.Length > (i = Event.current.button))
{
//Trying to invoke the method "void Activate()" present in every script in the list
onMouseDown[0].Invoke("Activate", 0);
}
onMDown = false;
}
}
}
Obviously, casting into MonoBehaviour was a bad choice, but i don’t see any other generic variable class for scripts. Anyone got any ideas?