Bark UI always under everything
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Bark UI always under everything
Hi guys, I started use template Buble Bark UI, and all my barks under everything.
Does someone know how to fix that?
Does someone know how to fix that?
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Re: Bark UI always under everything
Tony Li wrote: ↑Sat Sep 30, 2023 7:44 pm Hi,
Please see: How To: Make World Space Canvas Appear On Top Of Everything Else
I copied the template and UI layer was already - you can see it screenshot
- Attachments
-
- Screenshot 2023-10-04 at 11.56.22.png (752.16 KiB) Viewed 469 times
Re: Bark UI always under everything
Are you rendering the UI layer with a different camera that has a higher depth, as described in the link above?
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Re: Bark UI always under everything
If you want to use world space UIs, then yes. That's the correct way to do it. The process is documented in the link above.
Alternatively, you can switch to using a screen space UI. The Dialogue System Extras page has a "UI Smooth Follow" example that demonstrates how to do this.
Alternatively, you can switch to using a screen space UI. The Dialogue System Extras page has a "UI Smooth Follow" example that demonstrates how to do this.
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Re: Bark UI always under everything
Got it. But how can I attach this script to bark prefab? If prefab is spawned as clone, and I dont have it in my NPC object?Tony Li wrote: ↑Wed Oct 04, 2023 9:53 am If you want to use world space UIs, then yes. That's the correct way to do it. The process is documented in the link above.
Alternatively, you can switch to using a screen space UI. The Dialogue System Extras page has a "UI Smooth Follow" example that demonstrates how to do this.
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Re: Bark UI always under everything
I wrote my own script, and solve the problem.
Now - all barks are spawned under needed NPC.
If you want - I can share script and you use it.
Now - all barks are spawned under needed NPC.
If you want - I can share script and you use it.
Re: Bark UI always under everything
Hi,
Yes, please feel free to share the script here to help other people in the future. Thanks!
Yes, please feel free to share the script here to help other people in the future. Thanks!
-
- Posts: 13
- Joined: Fri Sep 22, 2023 7:35 pm
Re: Bark UI always under everything
Here:
using System;
using UnityEngine;
using UnityEngine.UI;
public class BarkAdjustCanvasAndPosition : MonoBehaviour
{
public Canvas canvas;
//public GameObject mainPanel;
void Start()
{
// Find the main camera in the scene
Camera mainCamera = Camera.main;
// Check if we found the main camera
if (mainCamera != null)
{
// Set Canvas rendering mode to Screen Space - Camera
canvas.renderMode = RenderMode.WorldSpace;
// Set the Render Camera to the main camera
canvas.worldCamera = mainCamera;
// Change the sorting layer of the Canvas to "Top"
canvas.sortingLayerName = "NPC";
// Find the parent GameObject (npc) that contains the Canvas
GameObject npc = transform.parent.gameObject;
Transform mainPanelTransform = canvas.transform.Find("Main Panel");
// Check if the parent GameObject (npc) and mainPanel variable are assigned
if (npc != null)
{
// Set the position of mainPanel under the parent GameObject (npc) (+2 units up)
Vector3 mainPanelPosition = new Vector3(npc.transform.position.x, npc.transform.position.y + 1f);
mainPanelTransform.position = mainPanelPosition;
}
else
{
Debug.LogError("Parent GameObject (npc) or mainPanel variable not assigned!");
}
}
else
{
Debug.LogError("Main Camera not found!");
}
}
}
using System;
using UnityEngine;
using UnityEngine.UI;
public class BarkAdjustCanvasAndPosition : MonoBehaviour
{
public Canvas canvas;
//public GameObject mainPanel;
void Start()
{
// Find the main camera in the scene
Camera mainCamera = Camera.main;
// Check if we found the main camera
if (mainCamera != null)
{
// Set Canvas rendering mode to Screen Space - Camera
canvas.renderMode = RenderMode.WorldSpace;
// Set the Render Camera to the main camera
canvas.worldCamera = mainCamera;
// Change the sorting layer of the Canvas to "Top"
canvas.sortingLayerName = "NPC";
// Find the parent GameObject (npc) that contains the Canvas
GameObject npc = transform.parent.gameObject;
Transform mainPanelTransform = canvas.transform.Find("Main Panel");
// Check if the parent GameObject (npc) and mainPanel variable are assigned
if (npc != null)
{
// Set the position of mainPanel under the parent GameObject (npc) (+2 units up)
Vector3 mainPanelPosition = new Vector3(npc.transform.position.x, npc.transform.position.y + 1f);
mainPanelTransform.position = mainPanelPosition;
}
else
{
Debug.LogError("Parent GameObject (npc) or mainPanel variable not assigned!");
}
}
else
{
Debug.LogError("Main Camera not found!");
}
}
}