private void Update() { if (!isAlive) { return; } fireImage.fillAmount = attack.RemainingCooldown / attack.AttackSpeed; movement.Move(movementJoystick.Direction); attack.Aim(aimJoystick.Direction, this); }
public void LookAtPlayer() { attack.Aim((playerTransform.position - transform.position).normalized); if (Physics.Raycast(attack.Head.transform.position, attack.Head.transform.forward, out hit, chaseDistance, layersToHit)) { GameObject hitobject = hit.transform.gameObject; if (hitobject.GetComponent <PlayerController>()) { attack.Shoot(); } } }
// the Update loop contains a very simple example of moving the character around and controlling the animation void Update() { // grab our current _velocity to use as a base for all calculations _velocity = _controller.velocity; if (_controller.isGrounded) { _velocity.y = 0; } if (Input.GetAxisRaw("Horizontal" + controllerName) > 0) { normalizedHorizontalSpeed = 1; if (transform.localScale.x > 0f) { transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z); } _attack.Aim(); if (_controller.isGrounded) { _animator.SetInteger("state", 1); } } else if (Input.GetAxisRaw("Horizontal" + controllerName) < 0) { normalizedHorizontalSpeed = -1; if (transform.localScale.x < 0f) { transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z); } _attack.Aim(); if (_controller.isGrounded) { _animator.SetInteger("state", 1); } } else { normalizedHorizontalSpeed = 0; if (_controller.isGrounded) { _animator.SetInteger("state", 0); _attack.Aim(); } } if (Input.GetAxisRaw("Vertical" + controllerName) > 0) { _attack.Aim(); } else if (Input.GetAxisRaw("Vertical" + controllerName) < 0) { _attack.Aim(); } if (Input.GetButton("Fire" + controllerName)) { _attack.DoAttack(); } else { _attack.CancelAttack(); } // we can only jump whilst grounded if (_controller.isGrounded && Input.GetButtonDown("Jump" + controllerName) && gameObject.GetComponent <Animator>().GetBool("die") == false) { _velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity); audioSource.clip = audioSources[0]; audioSource.Play(); _animator.SetInteger("state", 2); } // apply horizontal speed smoothing it var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction? _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor); // apply gravity before moving _velocity.y += gravity * Time.deltaTime; _controller.move(_velocity * Time.deltaTime); if (health == 0) { Debug.Log("dead"); } }