示例#1
0
        // Update is called once per frame
        void Update()
        {
            angryspeed = angrySpeedVariable.value;

            UpdateBubbleParticleSystem();

            if (dead)
            {
                timer += Time.deltaTime;

                float deathTime = 0.5f;
                float deathSize = deathSizeCurve.Evaluate(timer / deathTime);
                transform.localScale = new Vector3(deathSize, deathSize, deathSize);

                //Debug.Log("DeathSize: " + deathSize);

                if (timer >= deathTime)
                {
                    //Bubbles
                    bubbleParticleSystem.gameObject.transform.parent = transform.parent;
                    Destroy(bubbleParticleSystem.gameObject, 1f);
                    bubbleParticleSystem.Emit(3);

                    //Sparks
                    sparkParticleSystem.gameObject.transform.parent = transform.parent;
                    Destroy(sparkParticleSystem.gameObject, 1f);
                    sparkParticleSystem.Play();


                    //Damage
                    if (playerTransform.value != null)
                    {
                        if (Vector3.Distance(transform.position, playerTransform.value.position) < hitDistance + 1f)
                        {
                            Vector3 force = (playerTransform.value.position - transform.position).normalized * 10;
                            sisVariable.value.OnHit(null, 5f, force, transform.position);
                            //Debug.Log("Bill hit sis!");
                        }
                    }

                    Destroy(gameObject);
                }
                return;
            }
            if (playerTransform.value != null)
            {
                //If There is a Straight Path
                if (angry && CanSeePlayer())
                {
                    //Naive Pathfinding
                    waypointNavigator.StopNavigate();
                    Vector3 dirtoplayer = (playerTransform.value.position - transform.position).normalized;
                    charactercontroller.Move(angryspeed * dirtoplayer * Time.deltaTime);
                    dirtoplayer.y = 0;
                    Quaternion quatdir       = Quaternion.LookRotation(dirtoplayer);
                    float      rotationspeed = 5f;
                    transform.rotation =
                        Quaternion.Slerp(transform.rotation, quatdir, rotationspeed * Time.deltaTime);
                }
                else
                {
                    //Smart pathfinding
                    timer += Time.deltaTime;
                    if (timer > 0.25f)
                    {
                        timer = 0;
                        if (waypointNavigator.PathFinished)
                        {
                            waypointNavigator.StartNavigation(playerTransform.value.position);
                        }
                        // First time seeing the player.
                        if (angry == false)
                        {
                            if (CanSeePlayer())
                            {
                                angry = true;
                                audioSource.PlayOneShot(angrySound, 0.1f);
                                bubbleParticleSystem.Emit(5);
                                //Debug.Log("Bill saw the player");
                            }
                        }
                    }
                }
            }

            // Movement and rotation.
            if (!waypointNavigator.PathFinished)
            {
                float   speed = (angry ? angryspeed : normalspeed);
                Vector3 dir   = waypointNavigator.DirectionToWaypoint;
                charactercontroller.Move(transform.forward * speed * Time.deltaTime);
                dir.y = 0;
                Quaternion quatdir = Quaternion.LookRotation(dir);
                transform.rotation =
                    Quaternion.Slerp(transform.rotation, quatdir, rotationspeed * Time.deltaTime);
            }
            //Hit Sis!
            if (Vector3.Distance(transform.position, playerTransform.value.position) < hitDistance)
            {
                //Vector3 force = (playerTransform.value.position - transform.position).normalized * 25;

                //sisVariable.value.OnHit(null, 5f, force, transform.position);
                SetDead();
            }
        }