void Update() { // Movement float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); Vector2 movement = new Vector2(horizontal, vertical); rb.velocity = (movement * speed); // Dashing switch (dashState) { case DashState.Ready: var isDashKeyDown = Input.GetKeyDown(KeyCode.LeftShift); if (isDashKeyDown) { //thisVelocity = rigidbody.velocity //rigidbody.velocity = new Vector2(rigidbody.velocity.x * 5f, rigidbody.velocity.y); dashState = DashState.Dashing; } break; case DashState.Dashing: dashTime *= Time.deltaTime * 2; if (dashTime >= maxDash) { dashTime = maxDash; //rigidbody.velocity = thisVelocity; dashState = DashState.Cooldown; } break; case DashState.Cooldown: cooldownTime -= Time.deltaTime; if (cooldownTime <= 0) { cooldownTime = 0; dashState = DashState.Ready; } break; } // Aim and fire weapon on mouse 0 if (weapon != null) { weapon.AimWeapon(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (Input.GetMouseButton(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePos.z = 0; weapon.Fire(mousePos); } } }
public virtual void MoveToPlayer() { // Look at the player //transform.LookAt(target.position); //transform.Rotate(new Vector2(0, -90), Space.Self); // Walk to the player if (Vector2.Distance(transform.position, target.position) > attackRange) { Vector3 direction = (target.position - transform.position).normalized; rb.velocity = direction * speed * Time.deltaTime; } else { if (weapon != null) { weapon.AimWeapon(target.position); weapon.Fire(target.position); } } }