- Home /
New input system's send message does not work.
I am changing my code from the old to the new input system. I am using send message to detect the inputs, I am certain that the issue is a setting I have not changed, or a line of code I have missed, but I have checked everything in my code multiple times against various tutorials and other forum posts, so I think my code is fine and I just forgot to enable something. Here is my code if anyone is interested:
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
//random stuff would be here
public InputAction playerControls;
private void Awake()
{
//other unimportant stuff has been removed here
}
private void OnEnable()
{
playerControls.Enable();
}
private void OnDisable()
{
playerControls.Disable();
}
private void Update()
{
//other unimportant stuff has been removed
void OnJump()
{
if (jumpsleft > 0)
{
if (jumpCoolDown < 0)
{
body.velocity = new Vector2(body.velocity.x, jumpheight);
jumpsleft = jumpsleft - 1;
jumpCoolDown = 1.5f;
isJump = true;
}
}
}
//press d to move right
void OnRight()
{
body.velocity = new Vector2(speed, body.velocity.y);
}
//press a to move left
void OnLeft()
{
body.velocity = new Vector2(speed * -1, body.velocity.y);
}
//some other unimportant stuff
}
}
,I've been trying to change my scripts from the old input system to the new one, I am using the send message option to detect the inputs. For some reason, the player does not respond to the key presses. I think it is either a setting I haven't changed or something I missed out in the code. I have been looking around for quite a while to try and find answers and none of the ones I have found helped me, I probably just forgot to check a box or I missed a line of code, but if anyone has any ideas as to what I could have missed out then please tell me.
Answer by CodeMonkeyYT · Apr 21 at 09:08 AM
You are defining those functions inside Update so they are local functions. Did you do that intentionally? Define them outside the Update and it should work provided you have the exact names.
I made a tutorial covering the new Input System in detail here https://unitycodemonkey.com/video.php?v=Yjee_e4fICc