Beispiel #1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        MainSceneManager mainSceneManager = MainSceneManager.getMainSceneManager();
        AudioSource      audioSource      = GetComponent <AudioSource>();

        if (collision.gameObject.tag.Equals("chest"))
        {
            overlappingAttackableObject = collision.gameObject;
        }
        else if (collision.gameObject.CompareTag("RoboSnakeCrushDetector"))
        {
            RoboSnakeController roboSnakeController =
                collision.gameObject.transform.GetComponentInParent <RoboSnakeController>();
            roboSnakeController.die();
            mainSceneManager.addCurrentScore(roboSnakeController.points);
            audioSource.Play();
            bounce();
        }
        else if (collision.gameObject.CompareTag("AligatorCrushDetector"))
        {
            AligatorController aligatorController =
                collision.gameObject.transform.GetComponentInParent <AligatorController>();
            aligatorController.die();
            mainSceneManager.addCurrentScore(aligatorController.points);
            audioSource.Play();
            bounce();
        }
        else if (collision.gameObject.CompareTag("CrowCrushDetector"))
        {
            CrowController crowController =
                collision.gameObject.transform.GetComponentInParent <CrowController>();
            crowController.die();
            mainSceneManager.addCurrentScore(crowController.points);
            audioSource.Play();
            bounce();
        }
    }