示例#1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Player")
     {
         enemies = GameObject.FindGameObjectsWithTag("Enemy");
         if (enemies.Length == 0)
         {
             slime.GetComponent <Rigidbody2D>().velocity = Vector2.zero;
             slime.transform.position = new Vector3(-100, -100, 0);
             GameMech gmScript = gameMech.GetComponent <GameMech> ();
             gmScript.SendMessage("LevelClear");
             Destroy(gameObject);
         }
     }
 }
示例#2
0
    void OnCollisionEnter2D(Collision2D col)
    {
        string Tag = col.gameObject.tag;

        if (Tag == "Destroyer")
        {
            cutterNormal.SetActive(false);
            cutterRainbow.SetActive(false);
            transform.position = new Vector3(-50, -50, 0);
            myRB.velocity      = new Vector2(0, 0);
            pupad.SetActive(false);
            GameMech gamemechScript = gameMech.GetComponent <GameMech> ();
            gamemechScript.lives = gamemechScript.lives - 1;
            gamemechScript.SendMessage("DeployCannon");
        }
        else if ((Tag == "TileN") || (Tag == "TileW") || (Tag == "TileE") || (Tag == "TileS"))
        {
            if (!rainbowMode)
            {
                SendPlaySound(splashsound);
                collisionPoint = col.contacts[0].point;
                Color paintC = col.gameObject.transform.Find("paintL").gameObject.GetComponent <SpriteRenderer>().color; //Gets color of SpriteRenderer component of child 'paintL' of collider gameObject TileW etc.
                SR.color = paintC;                                                                                       //Paint layer color assigned to slime SpriteRenderer color.
                if (slicerMode)
                {
                    cutterNormal.GetComponent <SpriteRenderer> ().color = paintC;
                }
            }
        }
        else if (Tag == "Enemy")
        {
            Color Ecolor = col.gameObject.GetComponent <SpriteRenderer> ().color;
            if (Ecolor == SR.color || rainbowMode)
            {
                Vector3 objPos = col.gameObject.transform.position;
                SendPlaySound(poofSound);
                implode = Instantiate(impFX);
                implode.transform.position = objPos;
                implode.gameObject.GetComponent <SpriteRenderer> ().color = Ecolor;
                implode.SetActive(true);
                Transform scoreT = col.gameObject.transform.Find("Score");
                Destroy(col.gameObject);
                Destroy(implode, implode.GetComponent <Animator> ().GetCurrentAnimatorStateInfo(0).length + 0f);
                float score = scoreT.localPosition.x;
                if (halfscore)
                {
                    score = score / 2;
                }
                int gold = (int)(score / 5f);
                scoreThisLvl = scoreThisLvl + ((int)score);
                GameObject cloneScore = Instantiate(scoreSpawn);
                cloneScore.transform.GetChild(0).GetComponent <Text>().text = "+" + score.ToString();
                cloneScore.transform.parent     = canvas1.transform;
                cloneScore.transform.position   = objPos;
                cloneScore.transform.localScale = new Vector3(17.29167f, 17.29167f, 1f);
                GameObject cloneCoin = Instantiate(coinSpawn);
                cloneCoin.transform.GetChild(0).GetComponent <Text>().text = "+" + gold.ToString();
                cloneCoin.transform.parent     = canvas1.transform;
                cloneCoin.transform.localScale = new Vector3(12f, 12f, 1f);
                cloneCoin.transform.position   = objPos;
                goldThisLvl += gold;
                //OnCollisionExit2D (col);
            }
        }
    }