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. Dismiss Notice

OnTriggerEnter - First Initialization lag

Discussion in 'Scripting' started by KowalskiCZK, May 4, 2014.

  1. KowalskiCZK

    KowalskiCZK

    Joined:
    Feb 17, 2014
    Posts:
    20
    Hi, i am trying to create my first game. i
    This is simple KeyPad script, but when i build this game, and i activate the OnTriggerEnter cscript, the game freezes for a milisecond. After first Initialization works everything fine..no lag, everything is smooth.
    Do you know, what is the problem, and can you help me?
    P.s. when i play the game in the editor, everything works fine, even the first Initialization.
     
  2. KowalskiCZK

    KowalskiCZK

    Joined:
    Feb 17, 2014
    Posts:
    20
    someone please?
     
  3. sabin

    sabin

    Joined:
    Nov 24, 2012
    Posts:
    34
    you can do all Initialization on Start() function.
     
  4. KowalskiCZK

    KowalskiCZK

    Joined:
    Feb 17, 2014
    Posts:
    20
    You mean like this?

    function Start()
    {
    Player=GameObject.FindWithTag("Player");
    }
     
  5. sabin

    sabin

    Joined:
    Nov 24, 2012
    Posts:
    34
    yes. find which part of code makes lag and if it is because of initialization then move that part to Start or Awake
     
  6. KowalskiCZK

    KowalskiCZK

    Joined:
    Feb 17, 2014
    Posts:
    20
    Thank you so much for your help...
    is there any way, how to easily find the bad part of code?
     
  7. KowalskiCZK

    KowalskiCZK

    Joined:
    Feb 17, 2014
    Posts:
    20