I am trying to invoke the Actions in the derived class but nothing happens.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(PlayerInput))]
public abstract class CharacterInput : MonoBehaviour
{
protected PlayerInput input;
protected Action<InputAction.CallbackContext> OnMove;
protected Action<InputAction.CallbackContext> OnAttack;
protected Action<InputAction.CallbackContext> OnSpecial;
protected Action<InputAction.CallbackContext> OnBlock;
protected Action<InputAction.CallbackContext> OnGrab;
protected Action<InputAction.CallbackContext> OnJump;
// Start is called before the first frame update
void Start()
{
input = GetComponent<PlayerInput>();
InputActionMap fighterMap = input.actions.FindActionMap("Fighter");
fighterMap.FindAction("Move").performed += OnMove;
fighterMap.FindAction("Attack").performed += OnAttack;
fighterMap.FindAction("Special").performed += OnSpecial;
fighterMap.FindAction("Block").performed += OnBlock;
fighterMap.FindAction("Grab").performed += OnGrab;
fighterMap.FindAction("Jump").performed += OnJump;
}
// Update is called once per frame
void Update()
{
}
}
Here is the derived class
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class ExampleInput : CharacterInput
{
// Start is called before the first frame update
void Start()
{
OnAttack = callbackContext => Debug.Log(callbackContext.performed);
}
// Update is called once per frame
void Update()
{
}
}
"Attack" is bound to left click. At first I made CharacterInput not abstract and defined OnAttack to just print a line in the debug window, then when I added CharacterInput as a component instead of ExampleInput, it worked fine. Printed every time I left-clicked. But I want to be able to add children of CharacterInput as components to a game object, and have the OnWhatever actions defined there, but nothing happens.