Version: 2017.3
public Vector3 position ;

Descripción

La posición del transform en el espacio del mundo.

The position member can be accessed by the Game code. Setting this value can be used to animate the GameObject. The example below makes an attached sphere bounce by updating the position. This bouncing slowly comes to an end. The position can also be use to determine where in 3D space the transform.

using UnityEngine;

// Use Transform.position to bounce a sphere. // The sphere and a quad are colored using materials.

public class ExampleScript : MonoBehaviour { Vector3 velocity = new Vector3(0.0f, 1.0f, 0.0f); float floorHeight = 0.0f; float sleepThreshold = 0.05f; float gravity = -9.8f;

void Start() { transform.position = new Vector3(0.0f, 1.5f, 0.0f); }

void FixedUpdate() { if (velocity.magnitude > sleepThreshold || transform.position.y > floorHeight) { velocity += new Vector3(0.0f, gravity * Time.fixedDeltaTime, 0.0f); }

transform.position += velocity * Time.fixedDeltaTime; if (transform.position.y <= floorHeight) { transform.position = new Vector3(0.0f, floorHeight, 0.0f); velocity.y = -velocity.y; } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961