c# - 如何在Unity中正确移动游戏对象?

标签 c# unity-game-engine

我想移动一个Text对象,部分代码如下。

GameObject.transform.position = new Vector3(-210, -200, 0);

当我在Unity中执行并检查GameObject的posX时,它的值变成-1170(在1920x1080中),-1653.566(16:9)。但posY可以正常工作。我已将引用卷积设置为1920x1080,我认为这可能与分辨率设置有关。有什么不对的吗?谢谢。

最佳答案

如果你正在谈论 Unity ui 文本,你应该这样做。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UITestSO : MonoBehaviour 
{

    public Text textObject;
    void Start () 
    {

        //Position relative to parent transform
        textObject.rectTransform.localPosition = new Vector3 (-210, -200, 0);

        //Position in world space
        textObject.rectTransform.position = new Vector3 (-210, -200, 0);
    }
}

关于c# - 如何在Unity中正确移动游戏对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43774662/

相关文章:

c# - 为什么 "int"和 "sbyte"GetHashCode 函数生成不同的值?

C# 继承虚拟或重写

c# - EF6 : Renaming namespace using Code First Migrations

objective-c - Xcode 报告 CBCentralManagerDelegate 未找到

c# - 为多个应用程序创建安装程序

c# - IIS 托管 WCF 服务 : Integration tests and code coverage

shader - 如何获取 Unity 着色器属性的完整列表

c# - 当前上下文中不存在名称 IEnumerator

android - Unity Android 调试信息

Android - 在应用程序启动时加载 Unity3d 模型/ View ,但在不同的 Activity 中显示