Search Unity

Ark style teleport / spawn ui. Adding spawns to ui.

Discussion in 'Scripting' started by llJIMBOBll, Aug 17, 2017.

  1. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi, I'm creating a respawn screen with a image of the map and I would like to show spawn locations on a UI.

    when the player places a spawn point (sleeping bag, bed), I would like it to show up in the UI and allow interaction for a spawn script.

    I tried adding a ui button in a world space canvas to a game object and set to a new layer (PlayerSpawnPoint), so the main cam doesn't render it and adding a UI cam to render that layer from top down perspective.

    I've added the render texture to the UI and the spawn buttons are showing as they should but I cant interact with them.

    I've tried using a raycast and a 2nd raycast but nothing seems to work
    Code (CSharp):
    1. void Update ()
    2.     {
    3.         if (Input.GetMouseButtonDown (0)) {
    4.            
    5.             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    6.             RaycastHit hit;
    7.             // do we hit our portal plane?
    8.             if (Physics.Raycast (ray, out hit, MainDistance, MainLayer)) {
    9.                
    10.                 Debug.Log (hit.collider.gameObject);
    11.  
    12.  
    13.                 // convert the hit texture coordinates into camera coordinates
    14.                 Ray portalRay = portalCamera.ViewportPointToRay (hit.textureCoord);
    15.                 RaycastHit portalHit;
    16.                 // test these camera coordinates in another raycast test
    17.                 if (Physics.Raycast (portalRay, out portalHit, Distance, Layer)) {
    18.                    
    19.                     Debug.Log (portalHit.collider.gameObject);
    20.                 }
    21.             }
    22.         }
    23.     }
    Maybe someone can think of a better way to show newly placed spawn points to a UI and allow for some kind of button or interaction to call a script.

    Thanx Alot Jim