Example #1
0
    // Update is called once per frame
    void Update()
    {
        transform.position += (mSpeed * transform.up * Time.smoothDeltaTime);
        GlobalBehavior.WorldBoundStatus status =
            mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds);

        if (status != GlobalBehavior.WorldBoundStatus.Inside)
        {
            mGameManager.subtractEggCount();
            Destroy(this.gameObject);
        }
    }
Example #2
0
    void OnTriggerEnter2D(Collider2D other)
    {
        var         source = GetComponents <AudioSource>();
        AudioSource blast  = source[0];
        AudioSource no     = source[1];
        AudioSource bite   = source[2];

        if (other.gameObject.name == "Egg(Clone)")
        {
            mHits++;
            blast.Play();

            if (mHits > 2) // 3 hits and die
            {
                mGameManager.scoreIncrease();
                Destroy(this.gameObject);
            }
            else // stunned
            {
                mTimeStunned = Time.realtimeSinceStartup;
                mState       = EnemyState.Stunned;
                if (null != mRenderder)
                {
                    mRenderder.sprite = Resources.Load("Textures/stunned_student", typeof(Sprite)) as Sprite;
                }
            }
            mGameManager.subtractEggCount();
            Destroy(other.gameObject);
        }
        else if (other.gameObject.name == "Apple(Clone)")
        {
            bite.Play();
            mHits   -= 3;
            mState   = EnemyState.Scary;
            wasScary = true;
            if (null != mRenderder)
            {
                mRenderder.sprite = Resources.Load("Textures/scary_student", typeof(Sprite)) as Sprite;
            }
            Destroy(other.gameObject);
        }
    }