Hello Guest

Author Topic: Low FPS during Build  (Read 3323 times)

Baal

  • Newbie
  • *
  • Posts: 2
    • View Profile
Low FPS during Build
« on: January 06, 2014, 11:59:25 pm »
Hi. I want make game with terraforming, building roads etc. Using 2d Toolkit. I writen this code:

Code: [Select]
   Plane p = new Plane(Tmap.transform.forward, Tmap.transform.position);
      Ray ray = Camera.ScreenCamera.ScreenPointToRay (Input.mousePosition);
      //RaycastHit rayhit;

      float hitD = 0;
      if (p.Raycast(ray, out hitD))
      {
         float fx, fy;
         if (Tmap.GetTileFracAtPosition(ray.GetPoint(hitD), out fx, out fy))
         {
            xxx = (int)(fx);
            yyy = (int)(fy);
            // you know what tile you're hitting now
               Debug.Log("x: "+xxx+" y:"+yyy);
         }
      }
      if (Input.GetMouseButtonDown (0)) {
         Tmap.SetTile(xxx,yyy,1,5);
         Tmap.Build();
      }
To change Tile in TileMaps (change Tiles to Road Tiles) But every time when i click my FPS was falling from 70+ to 30 and my character ignore collision (jump over river) so i can't use this solution in game :( There is any other way to smooth tile changing?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Low FPS during Build
« Reply #1 on: January 07, 2014, 11:00:58 am »
Build WILL be expensive if you have colliders. As the docs say: "Avoid building tilemaps every frame if you use Unity colliders as it will likely be too slow for runtime use.". If you need to build stuff at runtime, disable colliders and manage it yourself, eg. building a "skin" of box colliders pulled out of a cache is one way of doing this efficiently.