This script works until the section of code I marked with a comment is added and i can’t understand why… I’m thinking about reworking my basic movement controls to something more written out that i know will work but i’d like to have this more simple and graceful code more than something basic. If anyone can tell me what I’m doing wrong that’d be awesome!
public class Player : MonoBehaviour
{
public float speed = 5f;
public Rigidbody2D rb;
[SerializeField]
private float dashMultiplier = 1f;
private Vector3 tempVect;
void Update()
{
/* if (Input.GetButton("Space"))
{
dashMultiplier = 1.3f;
} */
DashCheck(dashMultiplier);
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
tempVect = new Vector2(h, v);
tempVect = tempVect.normalized * speed * Time.deltaTime;
rb.MovePosition(rb.transform.position + tempVect);
if (Input.GetButtonUp("Up"))
{
rb.velocity = Vector3.zero;
}
else if (Input.GetButtonUp("Down"))
{
rb.velocity = Vector3.zero;
}
else if (Input.GetButtonUp("Left"))
{
rb.velocity = Vector3.zero;
}
else if (Input.GetButtonUp("Right"))
{
rb.velocity = Vector3.zero;
}
speed = 5f;
dashMultiplier = 1f;
}
void DashCheck (float dashMultiplier)
{
speed = speed * dashMultiplier;
}
}