Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Switching and activating UI elements outside of UI with game objects.

Discussion in 'UGUI & TextMesh Pro' started by JeiAsHei, Oct 20, 2015.

  1. JeiAsHei

    JeiAsHei

    Joined:
    Oct 20, 2015
    Posts:
    4
    Heya,

    Been looking but cant find a solid solution or example to give me pointers on this.

    Im looking to have an game object like a button, call an event on a UI element (speech bubble) when the button object is being pressed by the player.

    Also looking into how i can switch the UI elements without having multiple UI canvases going on and off. IE for creating a speech bubble based conversation where the text changes.

    Ive only managed to find an example of appearing text that uses the UI canvas on/off method. Seems very backwards if one wants to have multiple speech bubbles for example (would mean creating tons of canvases), some way to switch the content inside one canvas is what im looking for.

    Unity has tutorials for UI events, but they are all for actions within the UI itself.
     
  2. NeilW

    NeilW

    Joined:
    May 29, 2014
    Posts:
    40
    You can just enable/disable the game object that contains the UI (or instantiate, add to canvas and later destroy it)
     
  3. litebox

    litebox

    Joined:
    Aug 29, 2011
    Posts:
    158
    You can use OnClick() event to call methods outside button - in this case you can enable or create speech bubble, that not a button children.

    You can use one Canvas and many Windows or Bubbles inside it (set of game objects). Then you can use gameObject.SetActive true/false to enable active Window and disable all another. Or you can use Prefabs to create / remove Windows (or Bubbles) dynamically.
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    You can apply scripts which implement the Event interface handlers to enable 3D objects to work like any other UI object. So long as the object is visible through a canvas, World Space or Screenspace.

    I even show an example of this with the RTS selector in the UI Extensions project (link in sig), just check the tutorial video for the RTS selectable component.
     
  5. JeiAsHei

    JeiAsHei

    Joined:
    Oct 20, 2015
    Posts:
    4
    Thanks a bunch guys! These tips will help me move forward a great deal :)