Question by
LaskioGaming · Nov 04, 2016 at 05:51 AM ·
c#
All of a sudden Shift + A D stopped working
Out of nowhere Shift + A + D wont move my character, A or D by itself with shift will, and Shift + W A or S will work, Only A and D combined and also Up and Left combined. It worked earlier and I kept swapping stuff out in my code and cannot find anything that I changed as a problem. If anyone can help it would be greatly appreciated. Sorry for the messy code.
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private Animator anim;
private bool playerMoving;
private Vector2 lastMove;
private bool superSaiyan;
private bool spellCooldown;
public float playerDamage = 10f;
private bool spellDurationOn;
private Vector2 lastMoveSuper;
private bool isSprinting;
//private Vector2 lastMoveSprint;
private Rigidbody2D myRigidBody;
void Start()
{
anim = GetComponent<Animator>();
myRigidBody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update() {
if (spellDurationOn == true)
{
playerDamage = 10f * 3;
}
if (spellDurationOn == false)
{
playerDamage = 10f;
}
playerMoving = false;
{
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
//Move Right
//transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
myRigidBody.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, myRigidBody.velocity.y);
playerMoving = true;
lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
lastMoveSuper = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
//lastMoveSprint = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
//transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
myRigidBody.velocity = new Vector2(myRigidBody.velocity.x, Input.GetAxisRaw("Vertical") * moveSpeed);
playerMoving = true;
lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
lastMoveSuper = new Vector2(0f, Input.GetAxisRaw("Vertical"));
//lastMoveSprint = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
}
/*isSprinting = false;
if (playerMoving == true)
{
if (Input.GetAxisRaw("Fire3") > 0.5f) unneccesary
{
isSprinting = true;
}
}
*/
if (Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
//if (Input.GetAxisRaw("Horizontal") > 0.5 && Input.GetAxisRaw("Horizontal") < -0.5) if i want to ice skate
{
myRigidBody.velocity = new Vector2 (0f, myRigidBody.velocity.y);
}
if (Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
// if (Input.GetAxisRaw("Vertical") > 0.5 && Input.GetAxisRaw("Vertical") < -0.5) ice skate
{
myRigidBody.velocity = new Vector2 (myRigidBody.velocity.x, 0f);
}
//Animation Parameters
anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetBool("SuperSaiyan", superSaiyan);
anim.SetBool("SpellCooldown", spellCooldown);
anim.SetBool("SpellDurationOn", spellDurationOn);
anim.SetFloat("LastMoveX", lastMove.x);
anim.SetFloat("LastMoveY", lastMove.y);
anim.SetFloat("LastMoveSuperX", lastMoveSuper.x);
anim.SetFloat("LastMoveSuperY", lastMoveSuper.y);
//anim.SetFloat("LastMoveSprintX", lastMoveSprint.x);
//anim.SetFloat("LastMoveSprintY", lastMoveSprint.y);
//anim.SetFloat("LastMoveSprintX", lastMoveSuper.x);
//anim.SetFloat("LastMoveSprintY", lastMoveSuper.y);
anim.SetBool("IsSprinting", isSprinting);
}
//Need to add Damage when Super Saiyan is Active
void OnGUI()
{
if (spellDurationOn == false)
{
if (Input.GetAxisRaw("Fire3") > 0.5f)
{
//isSprinting = true;
StartCoroutine(SprintMode());
}
}
if ( isSprinting == false && spellCooldown == false)
{
if (Input.GetAxisRaw("Fire2") > 0.5f)
{
StartCoroutine(SuperSaiyanMode());
}
}
}
public IEnumerator SprintMode()
{
moveSpeed = 8;
yield return new WaitForSeconds(0f);
moveSpeed = 5;
}
public IEnumerator SuperSaiyanMode()
{
moveSpeed = 0;
superSaiyan = true;
yield return new WaitForSeconds(1.5f);
moveSpeed = 5;
spellDurationOn = true;
superSaiyan = false;
spellCooldown = true;
yield return new WaitForSeconds(5f);
spellDurationOn = false;
yield return new WaitForSeconds(30f);
spellCooldown = false;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612100019im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI button that displays on top of a clickable 2D Box Collider in the scene won't work 0 Answers
Gameobject spinning by itself. 2 Answers
Is there a way to make a script activate when you look at an object? 1 Answer
Blank Console Error on Empty Project with a Single C# Script 7 Answers
Animation clip only plays once when button is pressed, and then will not play again 2 Answers