Beispiel #1
0
    void Update()
    {
        //Debug.Log(transform.up);
        //return;
        if (isDead)
        {
            return;
        }

        if (isInForceField)
        {
            if (GameObject.FindGameObjectsWithTag("ForceField").Length <= 0)
            {
                isInForceField = false;

                audioSource.PlayOneShot(roarSFX);

                // change animation and collider
                anim.SetTrigger(flyForward);
                PlayFlyAnimation();

                transform.parent = null;

                // turn on UI
                BossHealthBG.SetActive(true);
                BossHealth.SetActive(true);
                bossText.SetActive(true);
            }

            return;
        }

        // start moving and attacking

        float delta = Time.deltaTime;

        // play roar sound effect
        if (isNOTChargeUp)
        {
            if ((roarTimer += delta) >= roarTimeLimit)
            {
                fireTimeLimit += 4.6f;                  // make sure the charge up sound doesn't play while the boss is roaring
                roarTimer      = 0.0f;
                roarTimeLimit  = Random.Range(LOWER_ROAR_TIMER, UPPER_ROAR_TIMER) + 4.5f;

                audioSource.PlayOneShot(roarSFX, 0.96f);
            }
        }


        #region Fire
        if (!isFireMode && ((fireTimer += delta) >= fireTimeLimit))
        {
            isFireMode         = true;
            isInFiringPosition = false;
            isNOTup            = true;  // a check to make sure it's right side up
        }

        if (isFireMode)
        {
            if (isInFiringPosition)
            {
                chargeUPAnimationTimer -= delta;
                if (chargeUPAnimationTimer <= 0.0f)
                {
                    // fire projectile
                    //Debug.Log("BOSS FIRE PROJECTILE");

                    // check if player collided into the fireball before it has the chance of
                    // being fired by the boss
                    if (fireball != null)
                    {
                        fireball.GetComponent <PlasmaFireball>().Fire(playerTransform);

                        if (playerHealthBar && playerHealthBar.HealthPoints() <= 0.0f)
                        {
                            audioSource.PlayOneShot(fireSFX, 0.3f);
                        }
                        else
                        {
                            audioSource.PlayOneShot(fireSFX);
                        }
                    }


                    // change animation back into movement
                    isNOTChargeUp = true;
                    PlayFlyAnimation();
                    chargeUPAnimationTimer = CHARGEUP_ANIMATION_LIMIT;
                    isFireMode             = false;
                    fireTimer     = 0.0f;
                    fireTimeLimit = Random.Range(LOWER_FIRE_LIMIT, UPPER_FIRE_LIMIT);
                    return;
                }
            }
            else
            {
                // check if boss is right side up
                if (isNOTup)
                {
                    transform.LookAt(playerTransform);
                    //if(transform.up.x < 0.0f || transform.up.y < 0.0f || transform.up.z < 0.0f) { // flip right side up
                    //	transform.Rotate(zAxis, 160.0f * Mathf.Deg2Rad);
                    //}

                    //// check if right vector is pointing down, if yes rotate a bit more
                    //if(transform.right.x < 0.0f || transform.right.y < 0.0f || transform.right.z < 0.0f) {
                    //	transform.Rotate(zAxis, 40.0f * Mathf.Deg2Rad);
                    //	//Debug.Log("Right: " + transform.right);
                    //}

                    isNOTup = false;
                }
                else
                {
                    // is the boss below the player?
                    if (transform.position.y < playerTransform.position.y)                      // make sure the dragon is really above the player
                    // now move until boss is above the player
                    {
                        transform.position = transform.position + (new Vector3(0.0f, speed * speedMultiplier, 0.0f));
                    }
                    else
                    {
                        //******************
                        // maybe delete this chunk of code
                        //*******************
                        // do we need to flip the boss around so the belly face the player
                        //float bellyDistance = (bellyObj.transform.position - playerTransform.position).magnitude;
                        //float backDistrance = (backObj.transform.position - playerTransform.position).magnitude;
                        //if(backDistrance < bellyDistance) {
                        //	transform.Rotate(xAxis, 180.0f * Mathf.Deg2Rad);
                        //}
                        //**************************



                        // boss is above the player
                        fireball      = Instantiate(plasmaFireBallFab, transform.position + (transform.rotation * fireballOffsetVec), Quaternion.identity);
                        isNOTChargeUp = false;
                        PlayAttackAnimation();
                        isInFiringPosition = true;
                    }
                }
            }

            return;
        }
        #endregion


        if (isRotatingTowardPlayer)
        {
            transform.Rotate(xAxis, tempRotateAngle);
            angleBetweenSelfAndPlayer -= tempRotateAngle;
            if (angleBetweenSelfAndPlayer <= 0.0f)
            {
                isRotatingTowardPlayer = false;
            }


            //transform.Rotate(currentAxisRotation, tempRotateAngle);
            //if(tempRotateAngle >= 0.0f) {
            //	angleBetweenSelfAndPlayer -= tempRotateAngle;
            //	if(angleBetweenSelfAndPlayer <= 0.0f) {
            //		isRotatingTowardPlayer = false;
            //	}
            //}
            //else {
            //	angleBetweenSelfAndPlayer += tempRotateAngle;
            //	if(angleBetweenSelfAndPlayer >= 0.0f) {
            //		isRotatingTowardPlayer = false;
            //	}
            //}
        }
        else
        {
            // rotating
            if (isRotating)
            {
                if (isRotateX)
                {
                    transform.Rotate(xAxis, rotateX);
                }
                if (isRotateY)
                {
                    transform.Rotate(yAxis, rotateY);
                }
                if (isRotateZ)
                {
                    transform.Rotate(zAxis, rotateZ);
                }

                // rotate time is up so no more rotating
                if ((rotateTime += delta) >= rotateTimeLimit)
                {
                    isRotating = false;
                }
            }
            else
            {
                // rolette
                isRotating = System.Convert.ToBoolean(Random.Range(0, 2));
                if (isRotating)
                {
                    rotateTimeLimit = Random.Range(LOWER_ROTATETIME, UPPER_ROTATETIME);
                    rotateTime      = 0.0f;
                    isRotateX       = System.Convert.ToBoolean(Random.Range(0, 2));
                    isRotateY       = System.Convert.ToBoolean(Random.Range(0, 2));
                    isRotateZ       = System.Convert.ToBoolean(Random.Range(0, 2));

                    rotateX *= (Random.Range(0, 2) == 0 ? 1 : -1);
                    rotateY *= (Random.Range(0, 2) == 0 ? 1 : -1);
                    rotateZ *= (Random.Range(0, 2) == 0 ? 1 : -1);
                }
            }
        }

        transform.position = transform.position + (transform.rotation * (new Vector3(0.0f, 0.0f, speed)));

        Vector3 targetDir = playerTransform.position - transform.position;
        // if too far away from player turn back toward player.
        if (!isRotatingTowardPlayer && targetDir.sqrMagnitude >= (MAX_DISTANT_FROM_PLAYER * MAX_DISTANT_FROM_PLAYER))
        {
            angleBetweenSelfAndPlayer = Vector3.Angle(transform.forward, targetDir) * Mathf.Deg2Rad;
            isRotatingTowardPlayer    = true;
            isRotating = false;

            tempRotateAngle = ROTATE_ANGLE;
            //currentAxisRotation = xAxis;

            //Debug.Log(angleBetweenSelfAndPlayer);
            //// which axis to rotation from
            //float absX = Mathf.Abs(targetDir.x);
            //float absY = Mathf.Abs(targetDir.y);
            //float absZ = Mathf.Abs(targetDir.z);

            //tempRotateAngle = ROTATE_ANGLE;

            //// default to rotate via the x axis
            //if(absY > absX && absY > absZ) {
            //	if(Random.Range(0, 2) == 0) {
            //		currentAxisRotation = zAxis;
            //	}
            //	else {
            //		currentAxisRotation = xAxis;
            //	}
            //}
            //else if(absZ > absX && absZ > absY) {
            //	if(Random.Range(0, 2) == 0) {
            //		currentAxisRotation = yAxis;
            //	}
            //	else {
            //		currentAxisRotation = xAxis;
            //	}

            //	if(targetDir.z >= 0.0f) {
            //		tempRotateAngle = -ROTATE_ANGLE;
            //		angleBetweenSelfAndPlayer *= -1;
            //	}
            //}
            //else {
            //	// default to rotate via the x axis
            //	currentAxisRotation = xAxis;
            //	if(targetDir.x >= 0.0f) {
            //		tempRotateAngle = -ROTATE_ANGLE;
            //		angleBetweenSelfAndPlayer *= -1;
            //	}
            //}
        }
    }