更改Unity中三维对象的位置



我需要一个简单的脚本来更改Unity3D上三维对象(.obj(的XYZ位置。我点击一个按钮,对象必须将其位置更改为新的特定位置。我不知道C#。你能帮我吗?对不起我的英语

创建一个空的游戏对象并将此脚本拖到上面。

using UnityEngine;
public class LocationController : MonoBehaviour 
{
// Drag the object you want to move into this field
[SerializeField] private GameObject _objectToChangeLocation;
// Enter your desired new location
[SerializeField] private Vector3 _newLocation;
// For your button component, drag the game object holding this script
// and select this method
public void ChangeLocation()
{
_objectToChangeLocation.transform.position = _newLocation;
}
}

最新更新