// Update is called once per frame void Update() { // only shoot if enemy is not berserk if (!hitBehavior.IsBerserk()) { if (shotTimer > shotDelay) { Shoot(); shotTimer = 0.0f; // Debug.Log("shooting"); } shotTimer += Time.deltaTime; } }
// Update is called once per frame void Update() { // update speed and deadzone if enemy is berserk if (hitBehavior.IsBerserk()) { maxSpeed = berserkSpeed; deadzone = berserkDeadzone; animator.SetBool("IsBerserk", true); } if (playerTransform != null) { positionToFollow = playerTransform.position; } float positionDifference = transform.position.x - positionToFollow.x; // change direction and flip sprite based on position relative to player // change laser spawn position based on direction moveDirection = 0.0f; if (positionDifference > 0.0f) { sr.flipX = true; laserSpawn.transform.localRotation = Quaternion.Euler(0.0f, 180.0f, 0.0f); laserSpawn.transform.localPosition = new Vector2(-originalSpawnTransform.x, originalSpawnTransform.y); if (positionDifference > deadzone) { moveDirection = -1.0f; } } else { sr.flipX = false; laserSpawn.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); laserSpawn.transform.localPosition = new Vector2(originalSpawnTransform.x, originalSpawnTransform.y); if (positionDifference < -deadzone) { moveDirection = 1.0f; } } animator.SetFloat("Speed", Mathf.Abs(moveDirection)); }