请问unity2D开发怎么让UI固定在某个位置?

一开始button按钮在图片中间

但是我人物移动之后按钮跟着移动了

 

请问有没有什么办法让UI不跟着移动呢

你的UI难道不是在UI层吗,别跟人物挂在一层就行了。

应该是你有脚本控制Button进行了移动吧,Canvas下的组件回相对屏幕保持位置固定

搞清楚屏幕坐标和世界坐标的关系你就懂了

 Vector2 v2Pos = Camera.main.WorldToScreenPoint(lockPos);
                Vector2 uipos = new Vector2();
                bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(UIRoot.Instance.Canvas.transform as RectTransform, v2Pos, UIRoot.Instance.UICamera, out uipos);
                if (isRect)
                    GetComponent<RectTransform>().anchoredPosition = uipos;

lockPos是我需要固定的ui坐标对应的世界坐标