Пример #1
0
 // Update is called once per frame
 void Update()
 {
     //check whether the intro is over
     if (IntroController.instance.playGame)
     {
         playGame();
         IntroController.instance.playGame = false; //so we dont repeatedly call playgame()
     }
     moneyText.GetComponent <Text>().text = "$" + money.ToString();
     if (Input.GetMouseButtonDown(0) && !MessageController.instance.routeOn)
     {
         //if click menu item
         int        index   = getTile(Input.mousePosition); //dont conver to world points, screen points good
         GameObject firstGO = gameBoard[index];             //check if null
         string     nameGO  = "";
         if (firstGO != null)
         {
             nameGO = firstGO.tag;                //if something exists on tile, then we can check what it is
         }
         worldPosition = getCenterTile(index);
         if (MessageController.instance.scheduleOn)
         {
             if (index < 36)
             {
                 //check if its an industry
                 if (gameBoard[index] != null && gameBoard[index].tag == "industry")
                 {
                     industryIndex = index;
                     if (prevDepart != -1) //change last tile back to original color
                     {
                         Background.instance.changeBoardTileSprite(prevWorldPosition, greenGrass);
                         markDestinations(prevDepart, greenGrass);
                         destroyDeadlineText();
                     }
                     addDeadlineText(index);              //instantiate new deadline objects
                     Background.instance.changeBoardTileSprite(worldPosition, greenerGrass);
                     markDestinations(index, destSprite); //loop through allFactories, mark all indices greenergrass
                     //change the color of all the destination tiles
                     prevDepart        = index;
                     prevWorldPosition = worldPosition;
                 }
             }
             return;
         }
         if (index > 35) //its a menu item
         {
             Debug.Log("you clicked index " + index);
             if (index == 36)
             {
                 placeObject = train;
             }
             //if (index == 37) placeObject = car;
             if (index == 37)
             {
                 placeObject = hor;
             }
             if (index == 38)
             {
                 placeObject = vert;
             }
             if (index == 39)
             {
                 placeObject = curve2;
             }
             if (index == 40)
             {
                 placeObject = curve1;
             }
             if (index == 41)
             {
                 placeObject = curve4;
             }
             if (index == 42)
             {
                 placeObject = curve3;
             }
             if (index == 43 && !MessageController.instance.scheduleOn && !MessageController.instance.routeOn && IndustryController.instance.depart != -1)
             {
                 //you clicked clock, opens a list of routes
                 //MessageController.instance.scheduleOn = true;
                 MessageController.instance.showSchedule(true);
             }
         }
         else if (placeObject != null)
         {
             string newObject = placeObject.tag;
             //if its a railroad we instantiate and/or add it to list of lists
             if (newObject == "curve1" || newObject == "curve2" || newObject == "curve3" || newObject == "curve4" || newObject == "Hor" || newObject == "Vert")
             {
                 //add railroad if nothings on the tile or a railroad is on the tile
                 if (index != 0 && (nameGO == "" || nameGO == "curve1" || nameGO == "curve2" || nameGO == "curve3" || nameGO == "curve4" || nameGO == "Hor" || nameGO == "Vert"))
                 {
                     if (money >= 10)
                     {
                         SoundManager.instance.PlaySingle(trackSound);
                         money -= 10; //each track costs $10
                         railroad[index].Add(placeObject);
                         placeGameObject(placeObject, index, worldPosition);
                         //scaleTrack(newObject, placeObject);
                         //change color
                         if (railroad[index].Count > 1)
                         {
                             Background.instance.changeBoardTileSprite(worldPosition, greenerGrass);
                         }
                     }
                 }
             }
             else   //not a railroad, instantiate only if there's nothing on the tile
             {
                 Debug.Log("train at starting tile " + trainBoard[0]);
                 if (gameBoard[index] == null && newObject != "train")
                 {
                     placeGameObject(placeObject, index, worldPosition);
                 }
                 else if (newObject == "train" && trainBoard[0] == null)
                 {
                     Debug.Log("instantiating train");
                     if (money >= 100)
                     {
                         money -= 100;
                         Vector2    startPosition = new Vector2(-4.12f * Background.instance.scaleFactor, -2.04f * Background.instance.scaleFactor); //hardcoding may cause problem
                         GameObject trainTile     = Instantiate(placeObject, startPosition, Quaternion.identity);
                         Background.instance.scaleTile(trainTile, .3f, .3f);
                         SoundManager.instance.PlaySingle(trainSound);
                         trainBoard[0] = trainTile;
                     }
                 }
             }
             placeObject = null;
         }
         //click on a train (starting index) or industry
         else if (trainBoard[index] != null) //nameGO=="train" || (
         {
             //clicked on a train
             TrainController tc = trainBoard[index].GetComponent <TrainController>(); //index is the train's starting location
             if (!tc.coroutineActive)
             {
                 tc.openPath = true;
                 startIndex  = index;
                 tc.StartCoroutine(tc.startTrain()); //start the train ALL ABOARD
             }
         }
         //cycles through railroads
         else if (nameGO == "curve1" || nameGO == "curve2" || nameGO == "curve3" || nameGO == "curve4" || nameGO == "Hor" || nameGO == "Vert")
         {
             //cycle
             if (railroad[index].Count > 1)
             {
                 Destroy(gameBoard[index]);
                 railroadIndex[index] += 1;
                 int        nextRailroad    = railroadIndex[index];
                 int        trackCount      = railroad[index].Count;
                 int        track           = nextRailroad % trackCount;
                 GameObject trackTile       = railroad[index][track]; //railroad holds list of tracks for each tile
                 GameObject trackTilePrefab = Instantiate(trackTile, worldPosition, Quaternion.identity);
                 scaleTrack(trackTile.tag, trackTilePrefab);
                 gameBoard[index] = trackTilePrefab;
             }
         }
     }
 }