Beispiel #1
0
 void OnGUI()
 {
     if (GUI.Button(new Rect(x, y, width, height), "Barricade"))
     {
         // check if the player has enough coins to purchase barricade
         if (coins >= barricadeCost)
         {
             // if barricade is off and button clicked then create barricade
             if (!barricadeOn)
             {
                 Vector3 barricadeSpawnPoint = new Vector3(barricadeX, -barricadeY, barricadeZ);      // spawn point
                 Instantiate(barricade, barricadeSpawnPoint, Quaternion.identity);                    // instantiate barricade
                 ScoreLabelScript scoreLabelScript = Camera.main.GetComponent <ScoreLabelScript> ();
                 scoreLabelScript.coinChanges = -barricadeCost;
                 barricadeOn    = true;                 // change the mode
                 barricadeCost += 2;
                 Camera.main.GetComponent <Progress>().barricadeMode = true;
             }
             else
             {
                 // if barricade on and button clicked then fortify the barricade(+50 hit points)
                 Camera.main.GetComponent <Progress>().fullBarricadeHealth += 50;
                 Camera.main.GetComponent <Progress>().barricadeHealth     += 50;
                 ScoreLabelScript scoreLabelScript = Camera.main.GetComponent <ScoreLabelScript> ();
                 scoreLabelScript.coinChanges = -barricadeCost;
                 barricadeCost += 2;
             }
         }
     }
 }
 void OnGUI()
 {
     if (GUI.Button(new Rect(x, y, width, height), "Creek"))
     {
         // check if player has enough coins to purchase creek
         if (coins >= creekCost)
         {
             // if creek is off and button clicked then create creek
             if (!creekOn)
             {
                 Vector3 creekSpawnPoint = new Vector3(creekX, -creekY, creekZ);              // spawn point
                 Instantiate(creek, creekSpawnPoint, Quaternion.identity);                    // instantiate creek
                 ScoreLabelScript scoreLabelScript = Camera.main.GetComponent <ScoreLabelScript> ();
                 scoreLabelScript.coinChanges = -creekCost;
                 creekOn    = true;
                 creekCost += 2;
             }
             else
             {
                 // if creek is on and button clicked then deepen the creek(decrease more speed)
                 CreekScript creekScript = GameObject.FindWithTag("Creek").GetComponent <CreekScript>();
                 if (creekScript.speedDecrease < 0.6)                      // knight min. speed = 0.1, archer min. speed = 0.3
                 {
                     creekScript.speedDecrease += 0.2f;
                     ScoreLabelScript scoreLabelScript = Camera.main.GetComponent <ScoreLabelScript> ();
                     scoreLabelScript.coinChanges = -creekCost;
                     creekCost += 2;
                 }
             }
         }
     }
 }
    void destroyCoinAndAddToScore()
    {
        Destroy(coin);
        ScoreLabelScript scoreLabelScript = Camera.main.GetComponent <ScoreLabelScript> ();

        scoreLabelScript.scoreChanges = score;
        scoreLabelScript.coinChanges  = 1;
    }