void Update()
    {
        if (gameObject.tag == "Player" && health <= 0)
        {
            GameScore.RegisterDeath(gameObject);

            health = 0;
            dead   = true;
            // Play the dying sound effect at the player's location.

            if (!checkLives)
            {
                playerLives.lives -= 1;
            }

            checkLives = true;

            //If the timer is greater than or equal to the time before the level resets...
            if (!playerEnd)
            {
                AudioSource.PlayClipAtPoint(deathClip, transform.position);
                playerEnd = true;
                dieSignals.SendSignals(this);
            }

            // Stop the footsteps playing.
            GetComponent <AudioSource>().Stop();
            if (damageEffect)
            {
                damageEffect.transform.rotation = transform.rotation;
                if (!damageEffectCentered)
                {
                    //Vector3 dir = fromDirection;
                    //dir.y = 0.0f;
                    damageEffect.transform.position = (transform.position + Vector3.up * damageEffectCenterYOffset);
                }
                damageEffect.GetComponent <EllipsoidParticleEmitter>().maxSize = 5;
                damageEffect.Emit();// (particleAmount);
                //  GameObject a = damageEffect.GetComponent<EllipsoidParticleEmitter>();

                gameTheme1.enabled = false;
                gameTheme2.enabled = false;
                if (playerLives.lives > 0)
                {
                    LevelReset(false);
                }
                else
                {
                    LevelReset(true);
                }

                // Destroy(gameObject);
            }

            foreach (GameObject siren in sirenGameObjects)
            {
                siren.GetComponent <AudioSource>().mute = true;
            }
        }
    }
Exemple #2
0
    private IEnumerator Fire()
    {
        startFireSignals.SendSignals(this);
        yield return(new WaitForSeconds(1));

        stopFireSignals.SendSignals(this);
    }
Exemple #3
0
    void FixedUpdate()
    {
        float turningWeight = Mathf.Abs(rigid.angularVelocity.y) * Mathf.Rad2Deg / 100.0f;
        float forwardWeight = rigid.velocity.magnitude / 2.5f;
        float turningDir    = Mathf.Sign(rigid.angularVelocity.y);

        // Temp, until we get the animations fixed
        GetComponent <Animation>()[walk.name].speed     = Mathf.Lerp(1.0f, GetComponent <Animation>()[walk.name].length / GetComponent <Animation>()[turnLeft.name].length * 1.33f, turningWeight);
        GetComponent <Animation>()[turnLeft.name].time  = GetComponent <Animation>()[walk.name].time;
        GetComponent <Animation>()[turnRight.name].time = GetComponent <Animation>()[walk.name].time;

        GetComponent <Animation>()[turnLeft.name].weight  = Mathf.Clamp01(-turningWeight * turningDir);
        GetComponent <Animation>()[turnRight.name].weight = Mathf.Clamp01(turningWeight * turningDir);
        GetComponent <Animation>()[walk.name].weight      = Mathf.Clamp01(forwardWeight);

        if (forwardWeight + turningWeight > 0.1f)
        {
            float newAnimTime = Mathf.Repeat(GetComponent <Animation>()[walk.name].normalizedTime * 2 + 0.1f, 1);
            if (newAnimTime < lastAnimTime)
            {
                if (Time.time > lastFootstepTime + 0.1f)
                {
                    footstepSignals.SendSignals(this);
                    lastFootstepTime = Time.time;
                }
            }
            lastAnimTime = newAnimTime;
        }
    }
 void OnSignal()
 {
     if (locked)
     {
         locked = false;
         unlockedSignal.SendSignals(this);
     }
 }
 // After the object is spawned, check each frame if it's still there.
 // Once it's not, activate the onDestroyedSignals and disable again.
 void Update()
 {
     if (spawned == null || spawned.activeInHierarchy == false)
     {
         onDestroyedSignals.SendSignals(this);
         enabled = false;
     }
 }
    void Update()
    {
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_WP_8_1 || UNITY_BLACKBERRY || UNITY_TIZEN
        if (!GLOBAL.isJSConnected)
        {
            if (state == false && joysticks[0].tapCount > 0)
            {
                mouseDownSignals.SendSignals(this);
                state = true;
            }
            else if (joysticks[0].tapCount <= 0)
            {
                mouseUpSignals.SendSignals(this);
                state = false;
            }
        }
#else
#if !UNITY_EDITOR && (UNITY_XBOX360 || UNITY_PS3)
        // On consoles use the right trigger to fire
        float fireAxis = Input.GetAxis("TriggerFire");
        if (state == false && fireAxis >= 0.2f)
        {
            mouseDownSignals.SendSignals(this);
            state = true;
        }
        else if (state == true && fireAxis < 0.2f)
        {
            mouseUpSignals.SendSignals(this);
            state = false;
        }
#else
        if (state == false && Input.GetMouseButtonDown(0))
        {
            mouseDownSignals.SendSignals(this);
            state = true;
        }

        else if (state == true && Input.GetMouseButtonUp(0))
        {
            mouseUpSignals.SendSignals(this);
            state = false;
        }
#endif
#endif
    }
Exemple #7
0
    public void OnDamage(int damage = 1)
    {
        health--;
        damageSignals.SendSignals(this, this);

        if (health == 0)
        {
            deathSignals.SendSignals(this, gameObject);
        }
    }
Exemple #8
0
 void OnTriggerStay(Collider other)
 {
     // If the player has entered the trigger sphere...
     if (other.gameObject == player)
     {
         if (DetectPlayer())
         {
             playerInsightSignal.SendSignals(this, lastPlayerPosition);
         }
     }
 }
Exemple #9
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            mouseDownSignals.SendSignals(this);
        }

        if (Input.GetMouseButtonUp(0))
        {
            mouseUpSignals.SendSignals(this);
        }
    }
Exemple #10
0
    void OnTriggerEnter(Collider other)
    {
        if (other.isTrigger)
        {
            return;
        }

        if (other.gameObject.tag == triggerTag || triggerTag == "")
        {
            enterSignals.SendSignals(this);
        }
    }
Exemple #11
0
 void OnTriggerExit(Collider other)
 {
     // If the player leaves the trigger zone...
     if (other.gameObject == player)
     {
         // ... the player is not in sight.
         if (!DetectPlayer())
         {
             playerInSight = false;
             playerOutsightSignal.SendSignals(this);
         }
     }
 }
    void Update()
    {
        idleWeight = Mathf.Lerp(idleWeight, Mathf.InverseLerp(minWalkSpeed, maxIdleSpeed, speed), Time.deltaTime * 10);
        animationComponent[idle.name].weight = idleWeight;

        if (speed > 0)
        {
            float smallestDiff = Mathf.Infinity;
            foreach (MoveAnimation moveAnimation in moveAnimations)
            {
                float angleDiff = Mathf.Abs(Mathf.DeltaAngle(angle, moveAnimation.angle));
                float speedDiff = Mathf.Abs(speed - moveAnimation.speed);
                float diff      = angleDiff + speedDiff;
                if (moveAnimation == bestAnimation)
                {
                    diff *= 0.9f;
                }

                if (diff < smallestDiff)
                {
                    bestAnimation = moveAnimation;
                    smallestDiff  = diff;
                }
            }

            animationComponent.CrossFade(bestAnimation.clip.name);
        }
        else
        {
            bestAnimation = null;
        }

        if (lowerBodyForward != lowerBodyForwardTarget && idleWeight >= 0.9f)
        {
            animationComponent.CrossFade(turn.name, 0.05f);
        }

        if (bestAnimation != null && idleWeight < 0.9f)
        {
            float newAnimTime = Mathf.Repeat(animationComponent[bestAnimation.clip.name].normalizedTime * 2 + 0.1f, 1);
            if (newAnimTime < lastAnimTime)
            {
                if (Time.time > lastFootstepTime + 0.1f)
                {
                    footstepSignals.SendSignals(this);
                    lastFootstepTime = Time.time;
                }
            }
            lastAnimTime = newAnimTime;
        }
    }
Exemple #13
0
    void Update()
    {
        if (state == false && Input.GetMouseButtonDown(0))
        {
            mouseDownSignals.SendSignals(this);
            state = true;
        }

        else if (state == true && Input.GetMouseButtonUp(0))
        {
            mouseUpSignals.SendSignals(this);
            state = false;
        }
    }
    void OnSignal()
    {
        bool locked = false;

        foreach (Lock lockObj in locks)
        {
            if (lockObj.locked)
            {
                locked = true;
            }
        }

        if (locked == false)
        {
            conditionalSignal.SendSignals(this);
        }
    }
Exemple #15
0
    void OnTriggerEnter(Collider other)
    {
        if (other.isTrigger)
        {
            return;
        }

        bool wasEmpty = (objects.Count == 0);

        objects.Add(other.gameObject);

        if (wasEmpty)
        {
            enterSignals.SendSignals(this);
            enabled = true;
        }
    }
Exemple #16
0
    void OnTriggerExit(Collider other)
    {
        if (other.isTrigger)
        {
            return;
        }

        if (objects.Contains(other.gameObject))
        {
            objects.Remove(other.gameObject);
        }

        if (objects.Count == 0)
        {
            exitSignals.SendSignals(this);
            enabled = false;
        }
    }
Exemple #17
0
    public void OnDamage(float amount, Vector3 fromDirection)
    {
        // Take no damage if invincible, dead, or if the damage is zero
        if (invincible)
        {
            return;
        }
        if (dead)
        {
            return;
        }
        if (amount <= 0)
        {
            return;
        }

        health -= amount;
        damageSignals.SendSignals(this);


//		Debug.Log("Health = "+health);
        // Enable so the Update function will be called
        // if regeneration is enabled
        if (regenerateSpeed > 0)
        {
            enabled = true;
        }



        // Die if no health left
        if (health <= 0)
        {
            //GameScore.RegisterDeath (gameObject);

            health = 0;
            dead   = true;
            dieSignals.SendSignals(this);
            enabled = false;

            SendMessageUpwards("EnemyDead", SendMessageOptions.DontRequireReceiver);
        }
    }
Exemple #18
0
 // After the objects are spawned, check each frame if they're still there.
 // Once they're not,
 void Update()
 {
     // Once the list is empty, activate the onDestroyedSignals and disable again.
     if (spawned.Count == 0)
     {
         onDestroyedSignals.SendSignals(this);
         this.enabled = false;
     }
     // As long as the list is not empty, check if the first object in the list
     // has been destroyed, and remove it from the list if it has.
     // We don't need to check the rest of the list. All of the entries will
     // end up being the first one eventually.
     // Note that only one object can be removed per frame, so if there's
     // a really high amount, there may be a slight delay before the list is empty.
     else if (spawned[0] == null || spawned[0].activeInHierarchy == false)
     {
         spawned.RemoveAt(0);
     }
 }
    /// <summary>
    /// 被攻击,不是u3d api函数
    /// </summary>
    public void OnDamage(float amount, Vector3 fromDirection)
    {
        // Take no damage if invincible, dead, or if the damage is zero
        if (invincible)
        {
            return;
        }
        if (dead)
        {
            return;
        }
        if (amount <= 0)
        {
            return;
        }

        // Decrease health by damage and send damage signals

        // @HACK: this hack will be removed for the final game
        //  but makes playing and showing certain areas in the
        //  game a lot easier

        /*
         #if !UNITY_IPHONE && !UNITY_ANDROID
         * if(gameObject.tag != "Player")
         *      amount *= 10.0f;
         #endif
         */

        health -= amount;
        damageSignals.SendSignals(this);
        lastDamageTime = Time.time;

        // Enable so the Update function will be called
        // if regeneration is enabled
        if (regenerateSpeed > 0)
        {
            enabled = true;
        }

        // Show damage effect if there is one
        if (damageEffect)
        {
            damageEffect.transform.rotation = Quaternion.LookRotation(fromDirection, Vector3.up);
            if (!damageEffectCentered)
            {
                Vector3 dir = fromDirection;
                dir.y = 0.0f;
                damageEffect.transform.position = (transform.position + Vector3.up * damageEffectCenterYOffset) + colliderRadiusHeuristic * dir;
            }
            // @NOTE: due to popular demand (ethan, storm) we decided
            // to make the amount damage independent ...
            //FIXME_VAR_TYPE particleAmount= Random.Range (damageEffect.minEmission, damageEffect.maxEmission + 1);
            //particleAmount = particleAmount * amount * damageEffectMultiplier;
            damageEffect.Emit();        // (particleAmount);
        }

        // Die if no health left
        if (health <= 0)
        {
            GameScore.RegisterDeath(gameObject);

            health = 0;
            dead   = true;
            dieSignals.SendSignals(this);
            enabled = false;

            // scorch marks
            if (scorchMark)
            {
                scorchMark.SetActive(true);
                // @NOTE: maybe we can justify a raycast here so we can place the mark
                // on slopes with proper normal alignments
                // @TODO: spawn a yield return new Sub() to handle placement, as we can
                // spread calculations over several frames => cheap in total
                Vector3 scorchPosition = GetComponent <Collider>().ClosestPointOnBounds(transform.position - Vector3.up * 100);
                scorchMark.transform.position    = scorchPosition + Vector3.up * 0.1f;
                scorchMark.transform.eulerAngles = new Vector3(scorchMark.transform.eulerAngles.x, Random.Range(0.0f, 90.0f), scorchMark.transform.eulerAngles.z);//y值随机0到90
            }
        }
    }
    public void  OnDamage(float amount, Vector3 fromDirection)
    {
        // Take no damage if invincible, dead, or if the damage is zero
        if (invincible)
        {
            return;
        }
        if (dead)
        {
            return;
        }
        if (amount <= 0)
        {
            return;
        }


        health -= amount;
        damageSignals.SendSignals(this);
        lastDamageTime = Time.time;

        // Enable so the Update function will be called
        // if regeneration is enabled
        //if (regenerateSpeed > 0)
        //    enabled = true;

        // Show damage effect if there is one
        if (damageEffect)
        {
            damageEffect.transform.rotation = Quaternion.LookRotation(fromDirection, Vector3.up);
            if (!damageEffectCentered)
            {
                Vector3 dir = fromDirection;
                dir.y = 0.0f;
                damageEffect.transform.position = (transform.position + Vector3.up * damageEffectCenterYOffset) + colliderRadiusHeuristic * dir;
            }

            damageEffect.Emit();    // (particleAmount);
            //  GameObject a = damageEffect.GetComponent<EllipsoidParticleEmitter>();
        }

        //// Die if no health left
        if (health <= 0 && gameObject.tag != "Player")
        {
            GameScore.RegisterDeath(gameObject);

            health = 0;
            dead   = true;
            dieSignals.SendSignals(this);
            //	enabled = false;
            //   Destroy(gameObject);
            //  LevelReset();
            // scorch marks
            if (scorchMark)
            {
                scorchMark.SetActive(true);

                Vector3 scorchPosition = GetComponent <Collider>().ClosestPointOnBounds(transform.position - Vector3.up * 100);
                scorchMark.transform.position = scorchPosition + Vector3.up * 0.1f;
                //scorchMark.transform.eulerAngles.y = Random.Range (0.0f, 90.0f);
                scorchMark.transform.eulerAngles = new Vector3(0.0f, Random.Range(0.0f, 90.0f), 0.0f);
            }
            if (scoreController != null)
            {
                scoreController.AddScore(scoreValue);
            }
        }
    }
Exemple #21
0
    void Update()
    {
        Vector3 direction = motor.movementDirection;            // 得到怪的移动方向

        direction.y = 0;

        // walkWeight 走路权重值,这里把方向向量的长度值赋给walkWeight,在之后的if判断中,如果walkWeight大于0.01表示要往前走
        float walkWeight = direction.magnitude;

        GetComponent <Animation>()[forwardAnim.name].speed = walkWeight;     // 把walkWeight赋值给动画的速度,表示走的距离越长,怪行走的速度也就越快,所以对应的行走动画效果也非常快
        GetComponent <Animation>()[rightAnim.name].speed   = walkWeight;
        GetComponent <Animation>()[backAnim.name].speed    = walkWeight;
        GetComponent <Animation>()[leftAnim.name].speed    = walkWeight;

        // 得到横向转动的角度。Mathf.DeltaAngle : u3d api, 计算给定的两个角之间最短的差异。
        float angle = Mathf.DeltaAngle(
            HorizontalAngle(tr.forward),
            HorizontalAngle(direction)
            );

        if (walkWeight > 0.01f)
        {
            float w;
            if (angle < -90)
            {
                w = Mathf.InverseLerp(-180, -90, angle);                 // Mathf.InverseLerp : U3D API, 计算两个值之间的Lerp参数。也就是value在from和to之间的比例值。返回的float值位于0到1之间
                GetComponent <Animation>()[forwardAnim.name].weight = 0; // 根据怪的移动方向角度值设置怪动画的权重值,以播放往哪个方向走的动画,比如小于-90就是往左走
                GetComponent <Animation>()[rightAnim.name].weight   = 0;
                GetComponent <Animation>()[backAnim.name].weight    = 1 - w;
                GetComponent <Animation>()[leftAnim.name].weight    = 1;
            }
            else if (angle < 0)
            {
                w = Mathf.InverseLerp(-90, 0, angle);
                GetComponent <Animation>()[forwardAnim.name].weight = w;
                GetComponent <Animation>()[rightAnim.name].weight   = 0;
                GetComponent <Animation>()[backAnim.name].weight    = 0;
                GetComponent <Animation>()[leftAnim.name].weight    = 1 - w;
            }
            else if (angle < 90)
            {
                w = Mathf.InverseLerp(0, 90, angle);
                GetComponent <Animation>()[forwardAnim.name].weight = 1 - w;
                GetComponent <Animation>()[rightAnim.name].weight   = w;
                GetComponent <Animation>()[backAnim.name].weight    = 0;
                GetComponent <Animation>()[leftAnim.name].weight    = 0;
            }
            else
            {
                w = Mathf.InverseLerp(90, 180, angle);
                GetComponent <Animation>()[forwardAnim.name].weight = 0;
                GetComponent <Animation>()[rightAnim.name].weight   = 1 - w;
                GetComponent <Animation>()[backAnim.name].weight    = w;
                GetComponent <Animation>()[leftAnim.name].weight    = 0;
            }
        }

        // 播放侧滑音效
        if (skiddingSounds)
        {
            if (walkWeight > 0.2f && !audioSource.isPlaying)
            {
                audioSource.Play();
            }
            else if (walkWeight < 0.2f && audioSource.isPlaying)
            {
                audioSource.Pause();
            }
        }

        if (footstepSounds && walkWeight > 0.2f)
        {
            float newAnimTime = Mathf.Repeat(GetComponent <Animation>()[forwardAnim.name].normalizedTime * 4 + 0.1f, 1);     // Mathf.Repeat : u3d api, 循环数值t,0到length之间。t值永远不会大于length的值,也永远不会小于0。

            if (newAnimTime < lastAnimTime)
            {
                if (Time.time > lastFootstepTime + 0.1f)
                {
                    footstepSignals.SendSignals(this);     // 这个挂的怪根物体,所以表示往怪根物体发消息,发的消息执行的行动是OnFootstep,所以也就是怪根物体上的FootstepHandler脚本会来响应,执行OnFootstep函数,播放类型为Spider(蜘蛛)类型的走路声音
                    lastFootstepTime = Time.time;
                }
            }
            lastAnimTime = newAnimTime;
        }
    }