J
J
JustHacker2017-04-27 08:46:41
C++ / C#
JustHacker, 2017-04-27 08:46:41

How to move an object in Unity 3D?

How to move an object from its place in a 2D game on Unity 3D. In volume like this:

using UnityEngine;
using System.Collections

public class Example: MonoBehavior {
    public GameObject Cube;
    
    void update {
        if (Input.GetKey(KeyCode.A)) {
            Cube.transform.Translate(-Vector3.right*Time.deltaTime);
        }
    }
}

And how to implement it in 2D (well, just move it to the right)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Gaydak, 2017-04-27
@JustHacker

I would like to clarify what kind of object?
If it’s a sprite, then just like in your example (And there is also Vector3, it’s just that you don’t have to change the Z coordinate)
see what kind of Translate
“types” are . but then you should describe.
In any case, it was worth describing what kind of object you were going to move)

G
GreatRash, 2017-04-27
@GreatRash

In the same way, only instead of Vector3 there will be Vector2.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question