Having problems with coding
So, im trying to create a dash attack for my character and my coding isn't working. below is the code i have and keeps giving me the error "An object reference is required to access non-static member `UnityEngine.Rigidbody2D.velocity' " Lines; 21, 22 68, 22 97, 22 33, 31 33. using System.Collections; using System.Collections.Generic; using UnityEngine; public DashState dashState; public float dashTimer; public float maxDash = 20f;
public Vector2 savedVelocity;
void Update()
{
switch (dashState)
{
case DashState.Ready:
var isDashKeyDown = Input.GetKeyDown(KeyCode.L);
if (isDashKeyDown)
{
savedVelocity = Rigidbody2D.velocity;
Rigidbody2D.velocity = new Vector2(Rigidbody2D.velocity.x * 3f, Rigidbody2D.velocity.y);
dashState = DashState.Dashing;
}
break;
case DashState.Dashing:
dashTimer += Time.deltaTime * 3;
if (dashTimer >= maxDash)
{
dashTimer = maxDash;
Rigidbody2D.velocity = savedVelocity;
dashState = DashState.Cooldown;
}
break;
case DashState.Cooldown:
dashTimer -= Time.deltaTime;
if (dashTimer <= 0)
{
dashTimer = 0;
dashState = DashState.Ready;
}
break;
}
}
}
public enum DashState { Ready, Dashing, Cooldown }
Your answer
Follow this Question
Related Questions
GL.End requires material.SetPass before! - Error Message 6 Answers
Various LoadAsset Errors after Upgrading to Unity 2018.3.13f1 1 Answer
My map I made in Blender will not show up in Unity correctly 0 Answers
What is happening, things multiply when moving view? 0 Answers
How do I solve this problem? 1 Answer