コード例 #1
0
 void OnCollisionEnter(Collision other)
 {
     if (other.collider.gameObject.tag == "Floor")
     {
         return;
     }
     if (other.collider.gameObject.tag != "Pellet")
     {
         string other_tag = other.collider.gameObject.tag;
         if (other_tag == "Ghost" || other_tag == "Player")
         {
             GhostAI g_ai = other.collider.gameObject.GetComponent <GhostAI>();
             if (g_ai.IsVulnerable())
             {
                 _score -= other_tag == "Ghost" ? ROBOT_GHOST_POINTS : PERSON_GHOST_POINTS;
                 if (other_tag == "Player")
                 {
                     PlayerController pc = other.collider.gameObject.GetComponent <PlayerController>();
                     pc.LoseLife();
                 }
                 AudioSource death_sound = other.collider.gameObject.GetComponent <AudioSource>();
                 death_sound.Play();
                 // other.transform.position = g_ai._ghost_start.transform.position;
                 g_ai.Reset();
             }
             else
             {
                 _score            -= other_tag == "Ghost" ? ROBOT_GHOST_POINTS : PERSON_GHOST_POINTS;
                 transform.position = _pacman_start.transform.position;
                 if (other_tag == "Player")
                 {
                     LoseLife();
                 }
             }
             SetCountText();
         }
     }
 }
コード例 #2
0
    public void ResetAll()
    {
        Time.timeScale = 1f;
        PacManAI pacman_ai = _pacman.GetComponent <PacManAI>();

        pacman_ai.Reset();
        Transform[] ghosts = _ghosts.GetComponentsInChildren <Transform>();
        foreach (Transform t in ghosts)
        {
            if (t.gameObject.tag == "Ghost" || t.gameObject.tag == "Player")
            {
                GhostAI gai = t.gameObject.GetComponent <GhostAI>();
                gai.Reset();
                if (t.gameObject.tag == "Player")
                {
                    PlayerController pc = t.gameObject.GetComponent <PlayerController>();
                    pc.Reset();
                }
            }
        }
        Transform[] pills = _pills.GetComponentsInChildren <Transform>();
        foreach (Transform t in pills)
        {
            if (t.gameObject.tag == "Pellet")
            {
                t.gameObject.SetActive(true);
            }
        }
        Transform[] big_ills = _big_pills.GetComponentsInChildren <Transform>();
        foreach (Transform t in big_ills)
        {
            if (t.gameObject.tag == "Super Pellet")
            {
                t.gameObject.SetActive(true);
            }
        }
        _finished = false;
    }