Search Unity

Object goes to different position on WebGL Build

Discussion in 'Scripting' started by bekiryanik, Aug 20, 2019.

  1. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Hello,
    In the project i change the cars position from script and it seems working pretty good and object goes to its true position in the Unity Editor but when i build my project and open in browser and when i request car's position change, it goes somewhere else. I tried localPosition and position codes it gives same position. The performance of the game on WebGL and Editor is same. I couldn't figure out is it a Unity bug or not. Has anyone experienced something like this before? If you have any idea about it, please let me know.

    I use Unity 2018.3.14f1 version.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    What code did you use to position the object? Does that code take into account the different size and/or aspect ratio of whatever platform it is running on? For instance if you say (100,100) on a small screen, it might be near the center, but on a massive 4k screen it would be far up in the left corner.

    This API can help you get the current size of the screen in pixels:

    https://docs.unity3d.com/ScriptReference/Screen.html
     
    bekiryanik and Joe-Censored like this.
  3. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Code (CSharp):
    1. playerCar.transform.localPosition = new Vector3(..., ..., ...)
    This is what i use. This error only happens with one of the cars. I have 7 cars in total and in the rest of the cars i don't have such a problem. I checked the car's center and it is same as the rest of the cars. I will check the link and i will try to find something useful. Thank you so much for your reply.