// Update is called once per frame void Update() { //Moving Left if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { mover.AccelerateInDirection(new Vector2(-1f, 0f)); projectileShooter.SetDirection(new Vector3(-1f, 0f)); //spriteRenderer.flipX = true; transform.rotation = Quaternion.Euler(transform.rotation.x, 180f, transform.rotation.z); animator.SetBool("running", true); } //Moving Right if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { mover.AccelerateInDirection(new Vector2(1f, 0f)); projectileShooter.SetDirection(new Vector3(1f, 0f)); //spriteRenderer.flipX = false; transform.rotation = Quaternion.Euler(transform.rotation.x, 0f, transform.rotation.z); animator.SetBool("running", true); } // Moving Up if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W)) { jumper.Jump(); } // If no keys are pressed let the animator know if (Input.anyKey == false) { animator.SetBool("running", false); } }
public void Update() { remainingPatrolTime -= Time.deltaTime; //there's still patrol time left, so accelerate in our patrol direction if (remainingPatrolTime > 0.0f) { controlledMover.AccelerateInDirection(new Vector2(movementDirection, 0.0f)); } //we're out of patrol time, so if we've come to rest by now, reverse direction and continue else if (!controlledMover.IsWalking()) { movementDirection *= -1; remainingPatrolTime = patrolTime; if (jumpsAtEnd) { Jumper jumper = controlledMover.GetComponent <Jumper>(); if (jumper != null) { jumper.Jump(); } } } }
public void Update() { if (Input.GetKey(KeyCode.RightArrow)) { controlledMover.AccelerateInDirection(new Vector3(1.0f, 0.0f)); } if (Input.GetKey(KeyCode.LeftArrow)) { controlledMover.AccelerateInDirection(new Vector3(-1.0f, 0.0f)); } if (Input.GetKey(KeyCode.Space)) { controlledMover.GetComponent <Jumper>().Jump(); } }
public void Update() { //we can use the convenience of Unity's input axes to get direction automatically. //bonus! this works with WASD and we can hook it up to work with controllers! controlledMover.AccelerateInDirection(new Vector3(Input.GetAxis("Horizontal"), 0.0f, 0.0f)); if (Input.GetButtonDown("Jump")) { controlledJumper.Jump(); } }
public void Update() { //if it's not safe to walk forwards anymore, stop patrolling in that direction if (!MovingForwardsIsSafe()) { remainingPatrolTime = 0.0f; } remainingPatrolTime -= Time.deltaTime; //there's still patrol time left, so accelerate in our patrol direction if (remainingPatrolTime > 0.0f) { controlledMover.AccelerateInDirection(new Vector2(movementDirection, 0.0f)); } //we're out of patrol time, so if we've come to rest by now, reverse direction and continue else if (!controlledMover.IsWalking()) { movementDirection *= -1; remainingPatrolTime = patrolTime; } }
public void Update() { controlledMover.AccelerateInDirection(targetDirection); }