Search Unity

Increasing speed over time

Discussion in 'Visual Scripting' started by Deleted User, Mar 4, 2021.

  1. Deleted User

    Deleted User

    Guest

    Hi all, I have a game and I want to increase the speed of the ground overtime. I have the following code but I'm not sure how to specify how long to take before it increases it's speed?

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Ground : MonoBehaviour
    4. {
    5.     public Material material;
    6.     public float speedMultiplier = 0.5f;
    7.     public float xVel = 0.1f;
    8.     Vector2 offset;
    9.     void Start()
    10.     {
    11.         material = GetComponent<Renderer>().material;
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.         offset = new Vector2(xVel, 0);
    18.         material.mainTextureOffset += offset * Time.deltaTime * speedMultiplier;
    19.     }
    20. }
     
  2. Gumpy54

    Gumpy54

    Joined:
    Apr 7, 2017
    Posts:
    6
  3. Deleted User

    Deleted User

    Guest

    Thanks for the reply, but what i'm making move faster overtime is the background. the character is just running on the spot, and I set the background on repeat. I assume the thread above is used for making an object gradually increase speed?