Search Unity

--->>>>>>>Unity 3d : I'm trying to make my program wait 0.1 seconds

Discussion in 'Physics' started by derekli21870, Sep 10, 2020.

  1. derekli21870

    derekli21870

    Joined:
    May 10, 2020
    Posts:
    6
    Hi , I'm trying to make a jump script and I need to make the script wait 0.1 seconds between each statement
    HERE
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class gravityControl : MonoBehaviour
    6. {
    7.  
    8.     public bool isGrounded;
    9.     Rigidbody rb;
    10.     void Start(){
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     void OnCollisionStay(){
    15.         isGrounded = true;
    16.      
    17.     }
    18.  
    19.     void Update(){
    20.         if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
    21.             transform.Translate(0f, 0.2f, 0f);
    22.             //wait 0.1 seconds <----------------------------------
    23.             transform.Translate(0f, 0.2f, 0f);
    24.             //wait 0.1 seconds<----------------------------------
    25.             transform.Translate(0f, 0.2f, 0f);
    26.             //wait 0.1 seconds<----------------------------------
    27.             transform.Translate(0f, 0.2f, 0f);
    28.             //wait 0.1 seconds<----------------------------------
    29.             transform.Translate(0f, 0.2f, 0f);
    30.             //wait 0.1 seconds<----------------------------------
    31.             transform.Translate(0f, 0.2f, 0f);
    32.             //wait 0.1 seconds<----------------------------------
    33.             transform.Translate(0f, 0.2f, 0f);
    34.             //wait 0.1 seconds<----------------------------------
    35.             transform.Translate(0f, 0.2f, 0f);
    36.             //wait 0.1 seconds<----------------------------------
    37.             transform.Translate(0f, 0.2f, 0f);
    38.             //wait 0.1 seconds<----------------------------------
    39.             transform.Translate(0f, 0.2f, 0f);
    40.             isGrounded = false;
    41.         }
    42.     }
    43. }
    44.  
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,428
    Use Coroutines (see here).

    Please note that you're asking this scripting question on the physics forum but your question has nothing to do with physics. We try our best to keep each forum focused on each subject is all.