- Home /
 
 
               Question by 
               deathgod2056 · Apr 12 at 04:42 PM · 
                rigidbody2dspeedfallingrigidbody.velocitytimer-script  
              
 
              Currently The speed increases per frame after first 13 seconds. How to make it change the fall speed after each 13 seconds? I tried resetting the unscaled time but i think it doesnot work.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class speed : MonoBehaviour
 {
     float clock;
     Rigidbody2D rb;
     // Start is called before the first frame update
     void Start()
     {
          rb = GetComponent<Rigidbody2D>();
          rb.drag = 5;
     }
 
     // Update is called once per frame
     void Update()
     {
           clock = Time.unscaledTime;
         //Debug.Log(clock);
 
           if (clock >= 13)
           {
             if(rb.drag > 0.1)
             {
                 Dragreducer();
                 clock = 0;
             }
             else
             {
                 Gravityreducer();
                 clock = 0;
             }
           }
 
     }
     void Dragreducer()
     {
         float percentageindex = 0.003f * 5;
         rb.drag -= percentageindex;
         Debug.Log("Drag " + rb.drag);
     }
     void Gravityreducer()
     {
         float percentageindexgravity = 0.003f * 1;
         rb.gravityScale += percentageindexgravity;
         Debug.Log("gravity " + rb.gravityScale);
     }
 }
 
 
              
               Comment
              
 
               
              Answer by Caeser_21 · Apr 12 at 04:57 PM
Maybe try clock += 1 * Time.deltaTime instead of clock = Time. unscaledTime... 
Your answer
 
             Follow this Question
Related Questions
Moving Object in constant speed in one axis while be able to control the object in all axis 1 Answer
How do I make it so the player cant spam the dash 1 Answer
how can I set a limit to the speed of the rigidbody2d in Unity ?? 1 Answer
How do I add forward velocity to a Rigidbody2D? 2 Answers
GameObject Fall Speed? 3 Answers