コード例 #1
0
    void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Collision detected with HMD.");
        Debug.Log("Collision with object name: " + collision.gameObject.name);
        Debug.Log("Collision with object tag: " + collision.gameObject.tag);

        if (collision.gameObject.tag == ObjectTags.Pellet)
        {
            if (collision.gameObject.name.Contains(ObjectNames.PowerPellet))
            {
                Debug.Log("We collided with a super pellet. Initiating Frightened mode.");
                Ghost.ApplyFrightenedModeToAllGhosts();
            }
            Destroy(collision.gameObject);
            audioSource.PlayOneShot(pelletEatSound, 0.3f);
            GhostsController.CheckGhostStartThresholds();
        }
        else if (collision.gameObject.tag == ObjectTags.Ghost)
        {
            var ghost = collision.gameObject.GetComponent <Ghost>();
            if (ghost != null && ghost.BehaviourState != BehaviourState.Frightened && ghost.BehaviourState != BehaviourState.Caught)
            {
                Debug.Log("We got caught by the ghost! TAG: " + collision.gameObject.tag);
                audioSource.PlayOneShot(pacmanDeath);
                //Physics.IgnoreCollision(collider, collision.collider);
            }
            else if (ghost.BehaviourState == BehaviourState.Frightened)
            {
                Debug.Log("We caught the ghost!");
                ghost.ActivateCaughtMode();
            }

            // TODO: Implement player death logic!
        }
        else if (collision.gameObject.name == ObjectNames.LeftPortalImage)
        {
            if (transform.position.x > 0)
            {
                Debug.Log("We used the left portal!");
                playPortalSound();
                teleportRight();
            }
        }
        else if (collision.gameObject.name == ObjectNames.RightPortalImage)
        {
            if (transform.position.x < 0)
            {
                Debug.Log("We used the right portal!");
                playPortalSound();
                teleportLeft();
            }
        }
    }