Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

SceneLoadingNotWorking

Discussion in 'Scripting' started by JacksonNull, Nov 13, 2015.

  1. JacksonNull

    JacksonNull

    Joined:
    Nov 3, 2015
    Posts:
    16
    #pragmastrict

    functionStart () {

    }

    functionUpdate () {
    if (transform.position.y == -9.8)
    if (transform.position.x == 251.61)
    if (transform.position.z == 0)
    {
    Application.LoadLevel("Scene2");
    }
    }



    im very new to this unity java scripting stuff and i could use y'alls help on this



    i dont know what im doing wrong but when i put my character at that position it doesnt spawn me onto the next scene

    -the next scene is in build settings
    -would love to know if there is an easier way to do this loading new levels in unity 5 thing
     
  2. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    One possible problem is that floating-point values are not precise. A quick floating-point primer:

    A "standard" 32-bit float has 24 bits of precision, and 8 bits of "mantissa". In practical terms, that means that a float can store about seven digits, and ranges from about 10^32 to 10^-32. That doesn't mean it's precise to seven digits. In general, you only get useful precision to about 0.0001 (or just under five digits). In addition, the only values that can be stored precisely, are ones that can be generated by: Dividing by 2, and adding numbers generated by dividing by 2. Why this is, is an entire subject of itself. So 0.5, 0.75, 0.875, 0.375, and so on, can be stored precisely. This, by the way, doesn't necessarily mean they are stored precisely.

    To sum up, you can write "251.61", but it might be storing "251.6099". What you want to do is round (for example, to integers) and compare that.

    tl;dr - Never trust the accuracy of a float or double.

    Suggested next topic for this subject: Colliders, and trigger zones.
     
    Last edited: Nov 13, 2015
  3. JacksonNull

    JacksonNull

    Joined:
    Nov 3, 2015
    Posts:
    16
    that didnt really help
    thanks for trying though
     
  4. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329
    Why dont just make a trigger that starts the next level when a player enter the trigger?
     
  5. JacksonNull

    JacksonNull

    Joined:
    Nov 3, 2015
    Posts:
    16
    that script always refuses to work

    I have a new script im trying to make but i'm new to the && operators and i could use some help


    here it is:



    #pragmastrict

    functionStart () {

    }

    functionUpdate () {
    if (transform.position.x = -6.1) && transform.position.y = -1.6)
    {
    Application.LoadLevel("Level2");
    }
    }
     
  6. cruising

    cruising

    Joined:
    Nov 22, 2013
    Posts:
    329

    Thry this, this should work if you take ur player into a collider that are a trigger
    Code (CSharp):
    1. public class LoadScene : MonoBehaviour {
    2.  
    3.     public int level;
    4.  
    5.     void OnTriggerEnter (Collider other)
    6.     {
    7.         //Is it the Player who enters the collider?
    8.         if (!other.CompareTag("Player"))
    9.             return; //If it's not the player dont continue
    10.         Application.LoadLevel(level);
    11.     }
    12. }