Пример #1
0
 //Called by player if this bad boy is buildable and turns him into a corresponding wall segment.
 public void Build()
 {
     //Switch the spritr while building.
     GetComponent <SpriteRenderer>().sprite = inProgBuild;
     //Update the build timer. Build is done when buildprog==1, so if we divide 1 by BuildTime, we get the frames needed to complete the build
     buildProg += 1 / BuildTime;
     if (buildProg < 1)
     {
         buildProgBar.fillAmount = buildProg;             //When less than one, update buildProgBar to match buildProg
     }
     else
     {
         buildProgBar.fillAmount = 1;  //Errors occur when thr progress bar goes past 1, so we cap it
     }
     //When fnished building, destroy the object, instantiate toBuild, and then mark the point on TheGrid as being occupied.
     if (buildProg >= 1)
     {
         Destroy(gameObject);
         Instantiate(toBuild, TheGrid.NearestPointOnGrid(transform.position), transform.rotation);
         TheGrid.CreateOrDestroy(TheGrid.NearestPointOnGrid(transform.position), true);
     }
 }