A
A
Artyom Dadashchyants2021-02-22 18:44:36
Unity
Artyom Dadashchyants, 2021-02-22 18:44:36

Buttons in Unity, what are they, and how does it usually end?

Problem. Let's say I have a button, when pressed, each frame should execute the code:

this.transform.Translate(0, speed * Time.deltaTime, 0);

How to do it? Standard OnClick doesn't want to execute this code every frame. The whole script looks like this:
using UnityEngine;

public class Movement : MonoBehaviour
{
    public float speed;
    // Start is called before the first frame update
    void Start()
    {
        
    }
    public void Left()
    {
        this.transform.Translate(0, speed * Time.deltaTime, 0);
    }
    public void Right()
    {
        this.transform.Translate(0, -speed * Time.deltaTime, 0);
    }
    void Update()
    {
        
    }
}


Thanks in advance!!!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question