Unity 6.3
0 онлайн 77 гостей 3 в системе
Вход

TransformHandle.up

Declaration

public Vector3 up;

Описание

Зеленая ось преобразования в мировом пространстве.

Манипуляции GameObjectположение на оси Y (зеленая ось) преобразования в мировом пространстве. В отличие Vector3.up, TransformHandle.up перемещает GameObject при одновременном рассмотрении вопроса о его ротации.

Когда GameObject поворачивается, зеленая стрелка представляет собой ось Y GameObject также меняет направление. TransformHandle.up перемещает GameObject в оси зеленой стрелки (Y).

Для перемещения GameObject по оси Y без учета вращения, см. Vector3.up.

using UnityEngine;

public class Example : MonoBehaviour { Rigidbody2D m_Rigidbody; float m_Speed;

void Start() { //Fetch the Rigidbody component you attach from your GameObject m_Rigidbody = GetComponent<Rigidbody2D>(); //Set the speed of the GameObject m_Speed = 10.0f; }

void Update() { if (Input.GetKey(KeyCode.UpArrow)) { //Move the Rigidbody upwards constantly at speed you define (the green arrow axis in Scene view) m_Rigidbody.linearVelocity = transformHandle.up * m_Speed; }

if (Input.GetKey(KeyCode.DownArrow)) { //Move the Rigidbody downwards constantly at the speed you define (the green arrow axis in Scene view) m_Rigidbody.linearVelocity = -transformHandle.up * m_Speed; }

if (Input.GetKey(KeyCode.LeftArrow)) { //rotate the sprite about the Z axis in the positive direction transformHandle.Rotate(new Vector3(0, 0, 1) * Time.deltaTime * m_Speed, Space.World); }

if (Input.GetKey(KeyCode.RightArrow)) { //rotate the sprite about the Z axis in the negative direction transformHandle.Rotate(new Vector3(0, 0, -1) * Time.deltaTime * m_Speed, Space.World); } } }