Question by
robinjk9 · Dec 19, 2019 at 08:37 PM ·
c#scripting probleminput
No input coming from using new input system, and variable not viewed in inspector.
Firstly, the line of code to attribute the dash action with the dash button, (button "A" on controller), I receive no action from the button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
[SerializeField] float moveSpeed = 5f;
[SerializeField] float dashSpeed = 10f;
[Space]
[SerializeField] float dashTime = 0.25f;
float timeToNextDash = 0f;
bool dashing = false;
[SerializeField] Controls controls;
Rigidbody2D rb;
Vector3 movement;
bool dash;
void Awake() {
**controls = new Controls();**
rb = GetComponent<Rigidbody2D>();
[COLOR=#ff0000]controls.Player.Dash.performed += ctx => Dash();[/COLOR]
//.Player.Dash.performed += Dash;
}
void OnEnable() {
controls.Player.Enable();
}
void OnDisable() {
controls.Player.Disable();
}
void Update() {
// Collect input for movement
var moveInput = controls.Player.Move.ReadValue<Vector2>();
movement = Vector3.ClampMagnitude(new Vector3 {
x = moveInput.x,
y = moveInput.y
}, 1f);
//dash = controls.Player.Dash.triggered;
}
void FixedUpdate() {
// Check if dashing, if not, move by input. Else, move by dash speed
if (!dashing) {
rb.velocity = movement * moveSpeed * Time.fixedDeltaTime;
}
else {
var direction = rb.velocity.normalized;
rb.velocity = direction * dashSpeed * Time.fixedDeltaTime;
}
// Check if dashing timer has expired. If so, no longer dashing.
if (timeToNextDash <= Time.deltaTime) {
dashing = false;
}
else if (dash) {
dashing = true;
timeToNextDash = Time.time + dashTime;
}
}
public void Dash() {
Debug.Log("Player dashed!");
}
}
on a different note, I am unable to see the controls variable in the inspector.
Comment
Your answer
Follow this Question
Related Questions
Issue toggling Particle system on/off using bool. 1 Answer
How to tilt a sprite based on pointer position? 1 Answer
Movement Sticking 0 Answers
Getting mouse input in screen (0,0) and drag mouse 0 Answers
Input does't work at all for me 1 Answer