Объявление
public Vector3(float x, float y, float z);Описание
Создает новый вектор с заданными компонентами x, y, z.
//Прикрепите этот скрипт к GameObject.
//Прикрепите компонент Rigidbody к GameObject (нажмите кнопку Добавить компонент в окне инспектора и перейдите в раздел Физика<Жесткое тело)
//Этот скрипт перемещает GameObject вверх, используя Vector3
с помощью UnityEngine;
public class Vector3CtorExample : MonoBehaviour
{
Vector3 myVector;
Rigidbody m_Rigidbody;
float m_Speed = 2.0f;
void Start()
{
//Set the vector, which you use to move the RigidBody upwards straight away
myVector = new Vector3(0.0f, 1.0f, 0.0f);
//Fetch the RigidBody you attach to the GameObject
m_Rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
//Move the RigidBody upwards at the speed you define
m_Rigidbody.velocity = myVector * m_Speed;
}
}
Объявление
public Vector3(float x, float y);Описание
Создает новый вектор с заданными компонентами x, y и устанавливает z
в ноль.