Описание
Положение Transform в мировом пространстве.
Свойство position объекта GameObject Transform, который доступен в редакторе Unity и через скрипты. Измените это значение, чтобы переместить GameObject. Получите это значение, чтобы найти GameObject в трехмерном мировом пространстве.
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
//movement speed in units per second
private float movementSpeed = 5f;
void Update()
{
//get the Input from Horizontal axis
float horizontalInput = Input.GetAxis("Horizontal");
//get the Input from Vertical axis
float verticalInput = Input.GetAxis("Vertical");
//update the position
transform.position = transform.position + new Vector3(horizontalInput * movementSpeed * Time.deltaTime, verticalInput * movementSpeed * Time.deltaTime, 0);
//output to log the position change
Debug.Log(transform.position);
}
}
Пример получает входные данные от горизонтальной и вертикальной осей и перемещает игровой объект вверх/вниз или влево/вправо, изменяя его положение.