This is all my code. Unity reads the input and the console reports a -1 to 1 value but for some reason the rb.velocity or something isnt working and it just randomly happened please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour
{
public Text healthDisplay;
public GameObject LosePanel;
public float speed;
private float input;
Rigidbody2D rb;
Animator anim;
public int health;
public GameObject explosion;
public float startDashTime;
private float dashTime;
public float extraSpeed;
private bool isDashing;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
healthDisplay.text = health.ToString();
}
private void Update()
{
if (Input.GetAxis("Horizontal") != 0)
{
anim.SetBool("isRunning",true);
} else {
anim.SetBool("isRunning",false);
}
if (Input.GetAxis("Horizontal") > 0)
{
transform.eulerAngles = new Vector3 (0, 0, 0);
} else if (Input.GetAxis("Horizontal") <0)
{
transform.eulerAngles = new Vector3 (0, 180, 0);
}
if (Input.GetKeyDown(KeyCode.Space) && (isDashing==false)){
speed+=extraSpeed;
isDashing=true;
dashTime=startDashTime;
}
if ((dashTime<=0)&&(isDashing==true)){
isDashing=false;
speed-=extraSpeed;
}else{
dashTime -= Time.deltaTime;
}
}
// Update is called once per frame
void FixedUpdate()
{
//stores player input
float input= Input.GetAxisRaw("Horizontal");
print (input);
rb.velocity = new Vector2( speed * input, rb.velocity.y);
//moving player
}
public void TakeDamage (int damageAmount)
{
health -= damageAmount;
healthDisplay.text = health.ToString();
if (health <= 0)
{
Destroy(gameObject);
Instantiate(explosion, transform.position, Quaternion.identity);
LosePanel.SetActive(true);
}
}
public void GainHealth (int healAmount)
{
health += healAmount;
healthDisplay.text = health.ToString();
}
}
,HERES EVERYTHING I GOT unity reads the inputs and prints -1 1 and 0 but the character still doesnt move
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Player : MonoBehaviour
{
public Text healthDisplay;
public GameObject LosePanel;
public float speed;
private float input;
Rigidbody2D rb;
Animator anim;
public int health;
public GameObject explosion;
public float startDashTime;
private float dashTime;
public float extraSpeed;
private bool isDashing;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
healthDisplay.text = health.ToString();
}
private void Update()
{
if (Input.GetAxis("Horizontal") != 0)
{
anim.SetBool("isRunning",true);
} else {
anim.SetBool("isRunning",false);
}
if (Input.GetAxis("Horizontal") > 0)
{
transform.eulerAngles = new Vector3 (0, 0, 0);
} else if (Input.GetAxis("Horizontal") <0)
{
transform.eulerAngles = new Vector3 (0, 180, 0);
}
if (Input.GetKeyDown(KeyCode.Space) && (isDashing==false)){
speed+=extraSpeed;
isDashing=true;
dashTime=startDashTime;
}
if ((dashTime<=0)&&(isDashing==true)){
isDashing=false;
speed-=extraSpeed;
}else{
dashTime -= Time.deltaTime;
}
}
// Update is called once per frame
void FixedUpdate()
{
//stores player input
float input= Input.GetAxisRaw("Horizontal");
print (input);
rb.velocity = new Vector2( speed * input, rb.velocity.y);
//moving player
}
public void TakeDamage (int damageAmount)
{
health -= damageAmount;
healthDisplay.text = health.ToString();
if (health <= 0)
{
Destroy(gameObject);
Instantiate(explosion, transform.position, Quaternion.identity);
LosePanel.SetActive(true);
}
}
public void GainHealth (int healAmount)
{
health += healAmount;
healthDisplay.text = health.ToString();
}
}