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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

help me about changing the pict

Discussion in 'Scripting' started by Jessennn, Aug 31, 2018.

  1. Jessennn

    Jessennn

    Joined:
    Aug 6, 2018
    Posts:
    10
    hai my name is jessen
    i currenlty working for some project but i got some problem that i really confuse how to handle it .
    i am newbie at unity ,so maybe its simple problem for u guys but not for me

    what i really want is changing sprites that already detected for after several seconds
    im trying to search youtube and trying to follow what they did but its not works
    thats why im calling for help
    please help me

    i send you these photo so that you know whats the problem is
    thankyou very much sir
    and its just came out with my first pictures but the pictures wont change after that .
    im really stuck in here please help.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    You assign local variable Timer = 3, then subtract Time.deltaTime from it.

    That will be about 3.0f - 0.0166f roughly, so that will never be below 0, which is your next if statement.

    Do you have a member variable called Timer that you are hiding with the local variable Timer?
     
  3. Jessennn

    Jessennn

    Joined:
    Aug 6, 2018
    Posts:
    10
    im doing that script because i see someone youtube channel .
    then what the solution sir ? thankyou for answering my question sir
     
  4. Jessennn

    Jessennn

    Joined:
    Aug 6, 2018
    Posts:
    10
    even im trying changes time.deltatime to 1f its still not changed hmmmm
     
  5. DaemonicDreams

    DaemonicDreams

    Joined:
    Aug 23, 2018
    Posts:
    41
    You need to initialize your timer and delay outside of your function.
    Code (CSharp):
    1. private float delay = 3f;
    2. private float timer = delay;
    3.  
    4. void Update() {
    5.     //Code before timer check here
    6.     timer -= Time.deltaTime;
    7.     if (timer <= 0)
    8.     {
    9.         //On timer...
    10.         timer = delay;
    11.     }
    12.     //...
    13. }
    if you write "public" instead of "private" when initializing the delay you can modify your delay in the inspector.
     
  6. Jessennn

    Jessennn

    Joined:
    Aug 6, 2018
    Posts:
    10



    upload_2018-8-31_12-49-45.png

    im already trying somehow but i dont know why everytime i try the only work is before timer -= time.deltatime.
    the only panel show the sprites is helmimg , its never change to handphoneimg2 and its not error T.T
    hmm help me please
     
  7. Jessennn

    Jessennn

    Joined:
    Aug 6, 2018
    Posts:
    10
    Code (CSharp):
    1.  if (mTrackableBehaviour.TrackableName == "HELM")
    2.         {
    3.             playSound("sound/gabungan");
    4.             uploadimage.sprite = (Sprite)Resources.Load<Sprite>(filepath + "helmimg") as Sprite;
    5.             timer -= Time.deltaTime;
    6.             if (timer <= 0)
    7.             {
    8.                 if(uploadimage.sprite = (Sprite)Resources.Load<Sprite>(filepath + "helmimg") as Sprite)
    9.                 {
    10.                     uploadimage.sprite = (Sprite)Resources.Load<Sprite>(filepath + "handphoneimg2") as Sprite;
    11.                     timer = delay;
    12.                     return;
    13.  
    14.                 }
    15.                 if (uploadimage.sprite = (Sprite)Resources.Load<Sprite>(filepath + "handphoneimg2") as Sprite)
    16.                 {
    17.                     uploadimage.sprite = (Sprite)Resources.Load<Sprite>(filepath + "helmimg") as Sprite;
    18.                     timer = delay;
    19.                     return;
    20.  
    21.                 }
    22.  
    23.  
    24.             }
    25.  
    26.  
    27.         }


    should i change it ?