c# - 如何使 RectTransform 跟随位于不同父级下的另一个 RectTransform?

标签 c# unity-game-engine game-engine

我正在尝试使用默认 anchor 设置创建一个 RectTransform,遵循右下对齐非拉伸(stretch)的 RectTransform。然而,它们之间总是存在着偏移。

我尝试过 GetWorldRect().center 并将其转换为 WorldPoint,但没有成功。使用变换。仅当两个 UIElement 都使用默认值锚定时,位置才有效。

谁能帮忙填写下面的方法体吗?

public static void FollowRectTransform(this RectTransform source, RectTransform target)
{
}

最佳答案

您可以使用Parent Constraint组件,使一个 Gameobject 表现得好像它是另一个 GameObject 的子级,以实现定位和缩放目的,包括 RectTransform。

关于c# - 如何使 RectTransform 跟随位于不同父级下的另一个 RectTransform?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60231806/

相关文章:

c# - 在 C# 中,如何在使用 WebClient.DownloadStringTaskAsync 方法时设置超时?

c# - 使用 ASP.NET Web API 在 HTTP POST 请求中发送 PDF 文件

java - 我无法在 Unity3D 中构建 Android 应用程序。错误 Gradle 初始化失败

android - 统一注销UnityEngine.Social

android - Android 的 2D (GFX) 引擎

python - 运行时错误 : could not find any library for SDL2_ttf

python - 访问搅拌器对象的旋转

c# - 如果没有发生任何更改,linq 查询是否会重新执行?

c# - Azure Webjob 服务的 Microsoft.Azure.ServiceBus.Message 支持