Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        if (string.CompareOrdinal(other.name, "Checkpoint") == 0)
        {
            CP_Checkpoint checkpoint = other.GetComponent <CP_Checkpoint>();
            if (checkpoint != null)
            {
                checkpoint.PlayAnimation();
            }

            if (_suicideLastPosition == Vector3.zero)
            {
                _sceneManager.SetSuicideEnabled(true);
            }

            _suicideLastPosition = transform.position;
        }

        if (!_damageInvulnerable)
        {
            if (string.CompareOrdinal(other.name, "Water") == 0)
            {
                Hurt();
            }
            else if (string.CompareOrdinal(other.name, "Fish") == 0)
            {
                Hurt();
            }
            else if (string.CompareOrdinal(other.name, "Ball") == 0)
            {
                Hurt();
            }
            else if (string.CompareOrdinal(other.name, "Apple") == 0)
            {
                CP_Chestnut chestNut = other.GetComponent <CP_Chestnut>();
                if (chestNut != null && chestNut._fishState == CP_Chestnut.BallState.E_FALLING)
                {
                    Hurt();
                }
            }
        }

        if (other.name.Contains("PowerUp"))
        {
            CP_PowerUp powerUp = other.GetComponent <CP_PowerUp>();
            if (powerUp != null)
            {
                if (_currentPowerUp != PowerUpType.E_NONE)
                {
                    ResetPowerUp();
                }

                AddPowerUp((PowerUpType)(powerUp.PowerUpType + 1));

                powerUp.Taken();
            }
        }
    }
    void GenerateSceneObjects(int mapPos, int sceneObjects, int powerUps, int powerUpPos, GameObject parentGO)
    {
        foreach (var objectType in Enum.GetValues(typeof(SceneObjectTypes)))
        {
            if ((SceneObjectTypes)objectType == SceneObjectTypes.E_NONE)
            {
                continue;
            }

            if ((sceneObjects & (int)objectType) != 0)
            {
                SceneObjectTypes objectToCreate = (SceneObjectTypes)objectType;
                GameObject       baseGO         = Resources.Load("Prefabs/SceneObjects/" + objectToCreate.ToString()) as GameObject;
                if (baseGO != null)
                {
                    GameObject newSceneBackground = Instantiate(baseGO);
                    newSceneBackground.transform.SetParent(parentGO.transform, false);

                    if ((SceneObjectTypes)objectType == SceneObjectTypes.E_CHECKPOINT && mapPos == _sceneMapLastChekpointIndex)
                    {
                        CP_Checkpoint checkpoint = newSceneBackground.GetComponentInChildren <CP_Checkpoint>();
                        if (checkpoint != null)
                        {
                            checkpoint.SetVictoryCheckpoint(this);
                        }
                    }
                }
            }
        }

        if (powerUps != -1)
        {
            GameObject powerUp = Instantiate(ScenePowerUps[powerUps]);
            powerUp.transform.SetParent(parentGO.transform, false);

            CP_PowerUp powerUpScript = powerUp.GetComponent <CP_PowerUp>();
            if (powerUpScript != null)
            {
                powerUpScript.SetPosition(powerUpPos);
            }
        }
    }