Beispiel #1
0
    //各アイテムに触れた時の挙動
    private void OnTriggerEnter2D(Collider2D other)
    {
        GameObject obj = other.gameObject;

        Debug.Log(obj.name);

        if (other.gameObject.CompareTag("item"))
        {
            player player;

            switch (obj.name)
            {
            case "Heal":
                GameObject   HPGauge = Canvas.transform.Find("HPGauge").gameObject;
                HPController hpCtl   = HPGauge.GetComponent <HPController>();
                hpCtl.SetHP(hpCtl.transform.childCount + 1);
                break;

            case "Coin":
                player = GetComponent <player>();
                player.CoinCounter();
                break;

            case "Muteki":
                player = GetComponent <player>();
                bool isMuteki = player.GetMuteki();

                //無敵の重複はしない
                if (!isMuteki)
                {
                    player.MutekiTime();
                }

                break;
            }
            Destroy(obj);
        }
    }
Beispiel #2
0
 void Start()
 {
     hp = 5;
     hpCtl.SetHP(hp);
     rb2d = GetComponent <Rigidbody2D>();
 }