As in the title, iI am trying to figure out how to use a button for multiple purposes in Unity. In
In my specific case for instance, iI 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 iI do not want to indefinitely attack every frame { StartCoroutine(GetComponent<Player_Melee>().FirstAttack()); } In the conditions iI make sure that iI 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, iI set the 'Interact_Alt' button to be the same as the 'Fire1' used in the attack script. The scripts actually work, however whenever iI check an object iI also perform an attack. How can i make so that when iI want to inspect an object iI do not attack?
I was considering create a new finite state similarly to the one iI use to attack e.g. 'PlayerState.interact', but then iI was wondering, how would unity give the priority to which command to use?
Another alternative would be to check if iI am in the range of some object when iI want to attack and if within range it inspects the object instead, but it seems to me a much more convoluted solutions.
Does anybody have any suggestionsHow should I solve this? Thanks in advance!