Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Splitscreen ui problem

Discussion in 'UGUI & TextMesh Pro' started by CaptainKirby, Mar 29, 2015.

  1. CaptainKirby

    CaptainKirby

    Joined:
    Dec 12, 2011
    Posts:
    36
    Hey,
    I hope someone is able to help me as I am in a bit of a bind :)
    I have a splitscreen game setup(several cam's with different viewport rects), and i am trying to have arrows(for each camera point at the other players(when they are not in view).

    What i have so far works technically, but all the arrows are moving in the middle of the screen, as if it is just one camera. however, when there are 3 cameras and one of the cams is larger, the arrows also follow that size.

    This is my current code :

    1. foreach(Transform plyr in players)
    2. {
    3. if(!plyr.GetComponent<CapsuleCollider>().IsVisibleFrom(cameraT))//custom function that checks if the player can be seen by cameraT(which is the individual camera
    4. {
    5. foreach(Image arrw in arrows)
    6. {
    7. if(arrw.GetComponent<ArrowFollow>().followId == plyr.GetComponent<PlayerId>().playerId)
    8. {
    9. Vector3 screenPosViewport = cameraT.WorldToViewportPoint(plyr.transform.position);
    10. Vector3 screenPosViewportClamped =newVector3(Mathf.Clamp(screenPosViewport.x,0.04f,0.96f),Mathf.Clamp(screenPosViewport.y,0.04f,0.96f),0);
    11. Vector3 v3 =newVector3(screenPosViewportClamped.x * cameraT.pixelWidth -(cameraT.pixelWidth/2), screenPosViewportClamped.y * cameraT.pixelHeight-(cameraT.pixelHeight/2),0);
    12. arrw.transform.localPosition = v3;
    13. }
    14. }
    15. }
    I have also attatched an image, trying to illustrate what is wrong(arrows point to where the arrows "should" be.

    Also, I am aware of using canvas world space, but I would rather not instantiate 6+ canvases, instead of just making this work :)

    Hope someone can help, thanks.
     

    Attached Files:

  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,688
    I'll be honest and say you probably shouldn't use UI for this scenario. Main reason being you are going to have to tackle the whole screenspace to worldspace conversion for figuring out which direction to point on each camera.

    Might be better to treat it like any other GO, either using a 3D arrow with it's forward matrix just pointing at the other character, or a 2D sprite doing the same on screen.

    My 5 pence worth.