In Ability Starter I need a held down W key to activate

zoicelols

Member
Unity Input has GetKey which is what I need in my custom ability starter because it detects if a key is being held down. Is there a way I can use GetLongPress from your input to work like that or what other way can I achieve the same goal.
 
I already tried to create a custom ability starter, but when I replaced my GetButtonDown with GetKey it underlines in red and can't work. What script do I need to modify and add GetKey to? PlayerInput?
 
Last edited:
GetKey isn't supported but you could create a custom starter that uses it: https://opsive.com/support/document...ntroller/character/abilities/ability-starter/

I am confused at your comment because it is so vague. You send me a link to a page I have already studied. I don't understand what you mean because when I tried to create a custom starter with GetKey it won't work. How is it that I can work around your custom player input to still use the unsupported GetKey?
 
You'll need to create a new Ability Starter class and within that implement GetKey. In this case you won't use the PlayerInput class since that doesn't support GetKey.
 
You'll need to create a new Ability Starter class and within that implement GetKey. In this case you won't use the PlayerInput class since that doesn't support GetKey.
Okay so you are saying to still inherit from the ability starter class? Or do you mean completely create my own ability starter class that I can then inherit from?

Right now I'm trying to use the CanInputStartAbility , but the way I observed it in the combotimeout script is how I'm attempting to use it. So if I'm not supposed to use the player input portion of it, then I'm kind of confused. Sorry I get lost a bit when it comes to code.
 
Last edited:
Actually I realized that I don't need get key at all and that when I moused over GetButton, the tooltip says it picks up if the button is being continuously held down instead of detecting only the frame that it was being pressed like GetButtonDown. So now it works as I want it to. :)

Code:
using UnityEngine;
using System.Collections;
using Opsive.UltimateCharacterController.Input;

namespace Opsive.UltimateCharacterController.Character.Abilities.Starters
{
    /// <summary>
  
    /// </summary>
    public class HoldForwardAttack : AbilityStarter
    {

 
        /// <summary>
        /// Can the starter start the ability?
        /// </summary>
        /// <param name="playerInput">A reference to the input component.</param>
        /// <returns>True if the starter can start the ability.</returns>
        public override bool CanInputStartAbility(PlayerInput playerInput)
        {

            if (playerInput.GetButton("Forward"))
            {
                if (playerInput.GetButtonDown("Fire1"))
                {
                    return true;
                }
                
            }

            return false;

        }
    
      

    }
}
 
Top