Exemple #1
0
 void Start()
 {
     fix           = GetComponent <FixInteraction> ();
     soundInstance = GetComponent <AudioSource> ();
     requireFix    = fix != null ? true : false;
     Active        = activeOnStart;
 }
Exemple #2
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Interactable"))
        {
            FixInteraction interaction = other.GetComponent <FixInteraction>();

            if (interaction != null)
            {
                if (interaction.IsBroken)
                {
                    //GameOver
                    GameManager.Instance.GameOver();
                }
            }
        }
    }
Exemple #3
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Interactable"))
        {
            FixInteraction interaction = other.GetComponent <FixInteraction>();

            if (interaction != null)
            {
                if (!interaction.IsBroken)
                {
                    if (interaction.transform.position.x > -5f && interaction.transform.position.x < 10f)
                    {
                        int random = Random.Range(0, 10);
                        if (random < 1)
                        {
                            interaction.Break();
                        }
                    }
                }
            }
        }
    }
Exemple #4
0
    IEnumerator StartGameRoutine(bool restart)
    {
        isStartingGame = true;

        if (!restart)
        {
            yield return(new WaitForSeconds(2.5f));

            onStartLoad.Invoke();
        }
        else
        {
            onRestartLoad.Invoke();
        }


        yield return(new WaitForSeconds(0.5f));

        timeText.text = settings[activeLevel].gameTime.ToString("F0");

        //Wood Broken
        int woodQuantity = settings[activeLevel].brokenWoodPieces;
        int loopTries    = 100;

        while (woodQuantity > 0 && loopTries > 0)
        {
            loopTries--;
            int random = Random.Range(0, settings[activeLevel].brokenPartsParent.childCount);

            if (settings[activeLevel].brokenPartsParent.GetChild(random).position.x <maxLeft || settings[activeLevel].brokenPartsParent.GetChild(random).position.x> maxRight)
            {
                continue;
            }

            FixInteraction interaction = settings[activeLevel].brokenPartsParent.GetChild(random).GetComponent <FixInteraction>();
            if (interaction)
            {
                if (!interaction.IsBroken)
                {
                    interaction.Break();
                    woodQuantity--;
                }
            }
        }

        //Rail Broken
        int railsQuantity = settings[activeLevel].brokenRailsPieces;

        if (railsQuantity > 0)
        {
            GameObject[] brokenRails = new GameObject[settings[activeLevel].brokenPartsParent.childCount];
            for (int i = 0; i < settings[activeLevel].brokenPartsParent.childCount; i++)
            {
                GameObject r = Instantiate(brokenRail, settings[activeLevel].brokenPartsParent.GetChild(i).position, settings[activeLevel].brokenPartsParent.GetChild(i).rotation) as GameObject;
                brokenRails[i] = r;
            }

            loopTries = 100;
            while (railsQuantity > 0 && loopTries > 0)
            {
                loopTries--;
                int random = Random.Range(0, brokenRails.Length);
                if (brokenRails[random].transform.position.x <maxLeft || brokenRails[random].transform.position.x> maxRight)
                {
                    continue;
                }
                FixInteraction interaction = brokenRails[random].GetComponent <FixInteraction>();
                if (interaction)
                {
                    if (!interaction.IsBroken)
                    {
                        interaction.Break();
                        railsQuantity--;
                    }
                }
            }
        }


        actualTime     = settings[activeLevel].gameTime;
        IsGameActive   = true;
        isStartingGame = false;
        IsGameFinished = false;

        if (trainRoutineVar != null)
        {
            StopCoroutine(trainRoutineVar);
        }

        //Train Start
        trainRoutineVar = StartCoroutine(TrainsRoutine());
    }