コード例 #1
0
ファイル: lvl1_egg.cs プロジェクト: EricJSoler/mp4
    // Update is called once per frame
    void Update()
    {
        transform.position += (mSpeed * transform.up * Time.smoothDeltaTime);
        lvl1_GB.WorldBoundStatus status =
            mGameManager.ObjectCollideWorldBound(GetComponent <Renderer>().bounds);

        if (status != lvl1_GB.WorldBoundStatus.Inside)
        {
            mGameManager.subtractEggCount();
            Destroy(this.gameObject);
        }
    }
コード例 #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 == "lvl1_egg(Clone)")
        {
            mHits++;
            blast.Play();

            if (mHits > 2) // 3 hits and die
            {
                mGameManager.subtractEnemyCount();
                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 == "lvl1_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);
        }
    }