- Home /
How to right-click a button on unity
Ok, so basically a button only detects left-click right? Well, is there a way to make it detect right click and execute code? Here is my script so far:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonManager : MonoBehaviour {
public bool aimTrigger = false;
public GameObject gun;
public void AIM()
{
if (aimTrigger)
{
gun.GetComponent<AimScript>().Aim = false;
aimTrigger = false;
}
else
{
if (!aimTrigger)
{
gun.GetComponent<AimScript>().Aim = true;
aimTrigger = true;
}
}
}
}
it calls the method AIM when the button is pressed, execpt the button can only be left clicked, not right-clicked. Is there a way around this? sorry for not explaining good
Answer by Harinezumi · Mar 06, 2018 at 03:01 PM
This has been asked and answered before here, with same solution posted twice on the forum:
https://forum.unity.com/threads/can-the-ui-buttons-detect-a-right-mouse-click.279027/
https://forum.unity.com/threads/ui-button-detecting-right-mouse-button.336111/
Your answer
Follow this Question
Related Questions
Activate 2 separate OnClick events, with the different Mouse Buttons 2 Answers
how to make a button click able after a few seconds 2 Answers
Checking if Button is not pressed 1 Answer
Cursor appearance change when mouse over a GUI button 2 Answers
IsPointerOverGameObject doing the opposite of what I want 0 Answers