Version: 2021.2

Vector3Constructor

切换到手册
public Vector3 (float x, float y, float z);

描述

使用给定的 x、y、z 分量创建新向量。

//Attach this script to a GameObject.
//Attach a Rigidbody component to the GameObject (Click Add Component button in the Inspector window and go to Physics<Rigidbody)
//This script moves a GameObject upwards using a Vector3
using 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 设置为零。

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961