Version: 2020.1
言語: 日本語
public Vector3 position ;

説明

The world space position of the Transform.

The position property of a GameObject’s Transform, which is accessible in the Unity Editor and through scripts. Alter this value to move a GameObject. Get this value to locate the GameObject in 3D world space.

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); } }

The example gets the Input from Horizontal and Vertical axes, and moves the GameObject up/down or left/right by changing its position.

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