Perform Action Only When Button is Pressed (Gamepad with Input System)
I'm trying to make it so my character's movement speed increases whenever I am pressing a certain button. The problem with the script I have is whenever I press the button, the player's movement speed increases and stays that speed even when I am not pressing the button. The solution is probably a simple "if/else if" script, but I am using Unity's Input System to control the player with a gamepad, so I think it's a little more complicated that using Input.GetkeyDown/Input.GetKeyUp.
I have the part of my script that controls the run mechanic bellow.
If anyone has a fix for this, please let me know.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ThirdPersonMovement : MonoBehaviour
{
PlayerControls controls;
public float movementSpeed = 7f;
void Awake()
//Controller input roles
{
controls = new PlayerControls();
controls.Gameplay.Run.performed += ctx => Run();
}
void Run()
//Bottom button
{
if()
{
movementSpeed = 10f;
}
else if()
{
movementSpeed = 7f;
}
}
}
Answer by shoc4555 · Jun 10, 2020 at 06:24 PM
i didn't get it "player's movement speed increases and stays that speed even when I am not pressing the button." if you are not pressing the speed will be same....