Exemple #1
0
    void OnTriggerEnter(Collider other)
    {
        //for some F*****G reason, coins and other powerups keep getting spawned exactly where the trophy is spawned at. im tired of trying to figuring out why
        if (other.CompareTag("PowerUp"))                                                                              // this is the other powerups tag
        {
            if (PowerUpType == PowerUp.Trophy || PowerUpType == PowerUp.CheckPoint || PowerUpType == PowerUp.Crystal) // this is the current power ups tag, and has to be set to Trophy or Checkpoints or Crystals
            {
                GameObject go = other.gameObject;
                if (go != null)
                {
                    CoinController    c = null;
                    PowerUpController p = null;
                    c = go.GetComponent <CoinController>();
                    p = go.GetComponent <PowerUpController>();

                    if (c != null)
                    {
                        gScript.SubtractLevelCoins(1);
                        c.KillThisCoin();
                    }

                    if (p != null)
                    {
                        p.KillThisPowerUp();
                    }
                }
                // there may be a weird issue with the light still hanging around. I think a previous calling function may be destroy the object, but perhaps not its light
                GameObject.Destroy(other.gameObject);
            }
        }


        // normal collision logic
        if (other.CompareTag("Player") || other.CompareTag("Dragon")) // allow the dragon to set off bombs but not collect power ups
        {
            if (gScript != null)
            {
                if (collectOneShot == false)
                {
                    if (PowerUpType == PowerUp.CheckPoint && !other.CompareTag("Dragon"))
                    {
                        gScript.SetCheckPoint(new Vector2(gameObject.transform.position.x, gameObject.transform.position.z));

                        cpColor             = Color.white;
                        rend.material.color = cpColor;
                        rend.material.SetColor("_Color", cpColor);

                        collectOneShot = true;
                    }
                    else if (PowerUpType == PowerUp.Bomb)
                    {
                        SetBombTimer();

                        bombSpin = 37;

                        collectOneShot = true;
                    }
                    else if (PowerUpType == PowerUp.Trophy && !other.CompareTag("Dragon"))
                    {
                        gScript.SetRoundOverTime(true); // set the round as being over and won
                        gScript.RemovePowerUpFromMasterList(gameObject.GetInstanceID());
                        collectOneShot = true;
                    }
                    else if (PowerUpType == PowerUp.Crystal && !other.CompareTag("Dragon") && !gScript.IsCrystalActive())
                    {
                        gScript.ActivateCrystal(gameObject.transform.position.x);
                        gScript.RemovePowerUpFromMasterList(gameObject.GetInstanceID());
                        collectOneShot = true;
                    }
                    else if (!other.CompareTag("Dragon"))
                    {
                        gScript.SetPowerUpType(PowerUpType);
                        gScript.RemovePowerUpFromMasterList(gameObject.GetInstanceID());
                        collectOneShot = true;
                    }
                }
            }
            else
            {
                Debug.Log("Game Controller not acquired.");
            }
        }
    }