コード例 #1
0
    //if something touches the dead area
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!executable)
        {
            return;
        }
        GameObject objTouched = collision.gameObject;

        //judge if it is a player
        if (thePlatformerManager.JudgePlayer(objTouched))
        {
            PFPlayer player = objTouched.GetComponent <PFPlayer>();
            player.DeathAndRespawn(deadReason);
        }
        else
        {
            //not character... destroy it to save resource?
            Destroy(objTouched);
        }
    }
コード例 #2
0
    //just imagine that player touched this, it will temporarily lose control for a period.

    //if someone touches it
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!executable)
        {
            return;
        }

        //judge if it is a player
        GameObject objTouched = collision.gameObject;

        if (thePlatformerManager.JudgePlayer(objTouched))
        {
            //here write down what happened.
            PFPlayer player = objTouched.GetComponent <PFPlayer>();
            if (totallyDeadly)
            {
                player.DeathAndRespawn(deadReason);
            }
            else
            {
                player.TakeDamage(damageWhenTouched, deadReason);
            }

            //freeze control
            objTouched.GetComponent <PF2DController>().FreezeControl(freezeTime);

            //push-Away effects
            if (pushAwaySpeed > 0f)
            {
                PushAwayWithSpeed(objTouched, pushAwaySpeed);
                Debug.Log("hi");
                return;
            }
            PushAway(objTouched, pushAwayForces);
        }
        else
        {
            //not character... destroy it to save resource?
            //Destroy(other.gameObject);
        }
    }