unity3d - Unity - Ortho Camera Size VS Screen Resolution -


i'm making 2d game launching objects towards eachother. complete. however, when run on different devices, offsets of gameobjects messed due different screen size. in unity editor, i'm using free aspect view, , i've created gameobjects camera size of 80, align perfectly. think problem here screen resolution messes display, , because i'm using fixed amount of unity units position gameobjects, displayed weirdly when run game on standalone. i've written pixel perfect camera script, doesn't seem help. camera pixel perfect, however, in order compensate, camera size turned extremely small, or extremely large. want same across devices , screen resolutions. main problem here want gui elements display next player standing. script here.

using unityengine; using unityengine.ui; using system.collections;  public class holdtimemultiplierplayerfollowcontroller : monobehaviour {      public float textyoffset = 50f;      public text holdtimemultiplierdisplay;      void update() {         vector3 position = camera.main.worldtoscreenpoint(transform.position);         holdtimemultiplierdisplay.gameobject.transform.position = new vector3(position.x, position.y + textyoffset, position.z);     }  } 

anyone got ideas?

btw,

all art 32x32. pixels units ratio 1 1. camera size in editor 81.92, when i'm using free aspect screen size of 686x269. @ measurements, displayed perfectly.

any appreciated. maybe script, or suggestion on how implement it?

other scripts (if see issues need resolved or improvements added, please tell me):

using unityengine; using unityengine.ui; using system.collections;  public class playermovementcontroller : monobehaviour {  private int holdtimemultiplier = 0; public int maxholdtimemultiplier = 215;  public text holdtimemultiplierdisplaytext; private rigidbody2d rbody;  void awake() {     rbody = getcomponent<rigidbody2d>();      if(rbody == null) {         debug.logerror ("no rigidbody2d detected on player.");     } }  void update() {     vector2 mouseposition = new vector2(camera.main.screentoworldpoint(input.mouseposition).x,                                          camera.main.screentoworldpoint(input.mouseposition).y);     vector2 mousedirectionfromplayer = mouseposition - new vector2(transform.position.x, transform.position.y);      if(input.getmousebutton(0)) {         if(holdtimemultiplier < maxholdtimemultiplier) {             holdtimemultiplier ++;         } else {             holdtimemultiplier = 0;         }     } else {         if(holdtimemultiplier != 0) {             rbody.addforce(mousedirectionfromplayer * holdtimemultiplier * 200);             holdtimemultiplier = 0;         }     }     holdtimemultiplierdisplaytext.text = holdtimemultiplier.tostring(); }  } 

...

using unityengine; using system.collections;  public class spawnnewobject : monobehaviour {  public gameobject[] useableobjects;  public transform spawnpoint;  void update() {     if(input.getkeydown(keycode.n)) {         var randomobject = random.range(0,useableobjects.length);         gameobject useableobject;         useableobject = instantiate(useableobjects[randomobject], spawnpoint.position, spawnpoint.rotation) gameobject;     } }  } 


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -