V
V
visgold2018-06-03 19:56:21
Android
visgold, 2018-06-03 19:56:21

How to speed up a 2D game in Unity over time?

Good day. There is a movement script:

using UnityEngine;

public class MoveObject : MonoBehaviour {

    [SerializeField]
    private float speed = 5f;

    private void Update()
    {
        if (transform.position.y > 6f)
        Destroy(gameObject);
        transform.position += new Vector3(0, speed * Time.deltaTime, 0);
    }

how to make it so that after, for example, 10 seconds, the speed increases by, for example, by 1. I would be very grateful for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Suren, 2018-06-03
@visgold

well, you can use Coroutine, where you just write a delay of 10 seconds, after which you increase the speed by 1.
You can simply enter a time variable of the Float type, and if it is not equal to zero, subtract Time from it.

D
drista4, 2020-12-10
@drista4

Wouldn't it be easier if we organize acceleration through a loop in which 1 will be added to some speed variable and affect the speed of the object in the game?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question