Transform 您所在的位置:网站首页 unity移动相机放在哪个函数 Transform

Transform

2023-09-14 22:37| 来源: 网络整理| 查看: 265

Transform.position切换到手册public Vector3 position ; 描述

世界空间中的变换位置。

GameObject 的 Transform 的 position 属性,可以在 Unity Editor 中以及通过脚本来访问该属性。变更该值可移动 GameObject。获得该值可在 3D 世界空间中定位此 GameObject。

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

该示例从水平和垂直轴获取输入,然后通过更改 GameObject 的位置将它向上/向下或向左/向右移动。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有