As in the title, I am trying to figure out how to use a button for multiple purposes in Unity.
In my specific case for instance, I am currently using the joystick button 0 (the A button) to perform a simple melee attack:
if (Input.GetButtonDown("Fire1") && currentState != PlayerState.attack && currentState != PlayerState.stagger) //second clause because I do not want to indefinitely attack every frame { StartCoroutine(GetComponent<Player_Melee>().FirstAttack()); } In the conditions I make sure that I am pressing the right button and determining in which state my player is (the state is then changed in the attack coroutine). In order to interact with a given object, I created a trigger to check that the player is within range to inspect the object:
if (Input.GetButtonDown("Interact_Alt") && playerInRange) { if (dialogueBox.activeInHierarchy) { dialogueBox.SetActive(false); } else { dialogueBox.SetActive(true); dialText.text = dialogue; } } In the Input manager settings in unity, I set the 'Interact_Alt' button to be the same as the 'Fire1' used in the attack script. The scripts actually work, however whenever I check an object I also perform an attack. How can i make so that when I want to inspect an object I do not attack?
I was considering create a new finite state similarly to the one I use to attack e.g. 'PlayerState.interact', but then I was wondering, how would unity give the priority to which command to use?
Another alternative would be to check if I am in the range of some object when I want to attack and if within range it inspects the object instead, but it seems to me a much more convoluted solutions.
How should I solve this?