- Home /
Using Canvas/Gui with splitscreen(several cameras)
Hi, I hope someone can shed some light on how the canvas in the new gui system works, if with several cameras. What I am trying to do is: Have x amount of cameras in scene(basically splitscreen with 2-4 players). On each camera i will have arrows pointing to the other players in the scene on the gui(if they are outside of the current players screen. I have most of it working, BUT there is one problem. The arrows are acting as if they are on the same camera, even though i tell it to use its own. My current code is as follows:
foreach(Transform plyr in players)
{
if(!plyr.GetComponent<CapsuleCollider>().IsVisibleFrom(cameraT)) //custom function that checks if the player can be seen by cameraT(which is the individual camera
{
foreach(Image arrw in arrows)
{
if(arrw.GetComponent<ArrowFollow>().followId == plyr.GetComponent<PlayerId>().playerId)
{
Vector3 screenPosViewport = cameraT.WorldToViewportPoint (plyr.transform.position);
Vector3 screenPosViewportClamped = new Vector3(Mathf.Clamp (screenPosViewport.x, 0.04f, 0.96f), Mathf.Clamp(screenPosViewport.y, 0.04f, 0.96f), 0);
Vector3 v3 = new Vector3(screenPosViewportClamped.x * cameraT.pixelWidth - (cameraT.pixelWidth/2), screenPosViewportClamped.y * cameraT.pixelHeight- (cameraT.pixelHeight/2), 0);
arrw.transform.localPosition = v3;
}
}
}
Also to note, i parent the arrow objects to the canvas in start which also works fine. What the code results in is basically the arrows moving in the right way, an the right size of their respective cameras, but in the middle of the screen, and not on the position of the cameras themselves.
THanks in advance!
Your answer
Follow this Question
Related Questions
How do I keep an ui element in side of the canvas when scaling? 1 Answer
Problem with build version 1 Answer
4.6 UI Canvas is smaller than normal 1 Answer
uGUI Mask Content 0 Answers
Draw minimap on panel 2 Answers