I am trying to position my Inventory panel. I chose the Lower Left Corner option. This…
- User
I am trying to position my Inventory panel. I chose the Lower Left Corner option. This is working great in 1920x1080, but when in 4k, the Panel disappear from screen and do not stick to the lower left corner of the screen. Why?
void SetInvPosition (){ PanelTrans.anchorMax = new Vector2(0.5f,0.5f); PanelTrans.anchorMin = new Vector2(0.5f,0.5f); PanelTrans.pivot = new Vector2(0f,0f);
switch(InvPosition) { case InvPositions.TopRightCorner: //Top Right corner PanelTrans.localPosition = new Vector3(Screen.width/2-PanelTrans.rect.width,-(PanelTrans.rect.height-Screen.height/2), 0); break; case InvPositions.LowerRightCorner: //Lower right corner PanelTrans.localPosition = new Vector3(Screen.width/2-PanelTrans.rect.width,-(Screen.height/2), 0); break; case InvPositions.TopLeftCorner: //Top Left corner PanelTrans.localPosition = new Vector3(-(Screen.width/2),-(PanelTrans.rect.height-Screen.height/2), 0); break; case InvPositions.LowerLeftCorner: //Lower Left corner PanelTrans.localPosition = new Vector3(-(Screen.width/2),-(Screen.height/2), 0); break; case InvPositions.Center: //Center PanelTrans.localPosition = new Vector3(-Panel.GetComponent<RectTransform>().rect.width/2,-Panel.GetComponent<RectTransform>().rect.height/2, 0); break; } } - Assistant
- User
Im trying to position a tooltip on screen. While this is working great in 1920x1080, i have issue in 4k, where the tooltip is not well positioned on screen as it is in 1920x1080. Why?
// Tooltip creation void OnGUI() {
if (!otherGroupedObj) { if (showTooltip && fixedToTheObject && over) { positionToScreen = Camera.main.WorldToScreenPoint(transform.position); cameraDistance = Vector3.Distance(Camera.main.transform.position, this.transform.position); if (textResized) tooltipStyle.fontSize = tooltipStyleShadow.fontSize = Mathf.RoundToInt(tooltipSize - (cameraDistance / 3)); GUI.Label(new Rect(positionToScreen.x + tooltipPosition.x - tooltipShadowPosition.x, -positionToScreen.y + Screen.height + tooltipPosition.y / (cameraDistance / 10) - tooltipShadowPosition.y, 100f, 20f), currentText, tooltipStyleShadow); GUI.Label(new Rect(positionToScreen.x + tooltipPosition.x, -positionToScreen.y + Screen.height + tooltipPosition.y / (cameraDistance / 10), 100f, 20f), currentText, tooltipStyle); if (tooltipUIPanel != null) { tooltipUIPanel.transform.localPosition = new Vector3(positionToScreen.x + tooltipPosition.x - Screen.width / 2f, positionToScreen.y - Screen.height / 2f + tooltipPosition.y / (cameraDistance / 10), positionToScreen.z); } } } } - Assistant
- User
Its not working, the tooltip does not stay at the position, its rotating around when i move the camera
- Assistant
- User
Ok that seems to work now, the tooltip appears where it should and stay where it is and do not rotate in the world anymore. Thanks for helping me fix UI Resolution
- Assistant
I'm glad to hear that the solution worked for you and that the tooltip now appears correctly without rotating in the world! Proper handling of UI elements in Unity can sometimes be tricky, especially when dealing with different screen resolutions and world-to-screen space transformations.
If you have any more questions or need further assistance with your project, feel free to ask. Happy coding!
- User
The currentText displayed on screen is shrinked in 4k, but not in 1920x1080. Why?
- Assistant
- User
Flawless! is there a way to set the text slightly to the right of the tooltip?
- Assistant
- User
Here, the tooltip is a gameobject with an image component attached to it. So you can think of an image appearing with text to the right. In the image, 2 child were added : a Textmeshpro and I wrote "E" (keyboard) and a Image with "X" (xbox controller). Let me explain: so the player knows that he has to press E in order to interact when using keyboard. This is meant for mouse and keyboard user. But my game supports controller, where the player needs to press "X" using xbox Controller. I need to update the tooltip so that if the user is using keyboard, we use the child textmeshpro, if the user is using a controller, we use the child Image. Is that doable here?
- Assistant
- User
Can't we just do it in the previous OnGUI method? Let say I do this : private TextMeshProUGUI keyboardTooltip; private Image controllerTooltip;
void Start() { keyboardTooltip = tooltipUIPanel.GetComponentInChildren(); controllerTooltip = tooltipUIPanel.GetComponentInChildren(); }
Then we might just need to adapt in the OnGUI method???
- Assistant
- User
I'm not using the new input system, sadly... so it does not detect anything here and the display of the tooltip does not work as before.
- Assistant
- User
Nope, not working as expected. The tooltip is not places in the screen as before, and the tooltip always display the controller even tho i'm moving around with mouse and keyboard.
- Assistant