Forum rules - please read before posting.

Changing a menu element's texture on runtime

Hi all, sorry to bother you again. But I was wondering if there's a way to change a texture in a menu at runtime? 

I have a HUD that will display the calendar date, weekday, and an icon of the current "weather" and I need to be able to set it either through an action or through scripting. So, I wanted to know, what would be the best approach to do this? I know I can change text in the labels with an action already, but I have no idea how I would go about changing the icon (which is just a sprite image). Currently the menu is an Unity UI menu, but I could use an AC menu if necessary, it's not a very complex HUD...

Anyways, any advice would be greatly appreciated.

Comments

  • It's easier to do in Unity UI, and you have three options:
    1. Have one menu element per-graphic and show/hide the correct one using the Menu: Change state Action as appropriate.  Can be laborious if you have many graphics.
    2. Attach an Animator to your UI that allows you to control the graphic through animation.  You can then use the Object: Animate Action to change which animation is played in-game.
    3. Write a custom Action that can change the Image's texture at any time.  To access the canvas of a Unity UI linked to AC:

    GameObject canvasObject = AC.PlayerMenus.GetMenuWithName ("MyMenu").canvas.gameObject.

  • Thanks! I had just figured out the first option, but I do have a good bit of weather icons so maybe I'll try using animation instead!

    PS: I hope you had a nice vacation... and heh, I think you mistyped the date you would be back. In my country we don't have bank holidays, so when I saw the alert that you would be back on april 3rd I got a bit confused, I thought it was an old message that I hand't noticed. :))
  • I should've taken the opportunity to take a year off .. :P
  • Hey that's a nice way to grab the canvas of a Unity UI! Thanks for the tip Chris. I was using:

    GameObject UIfolder = GameObject.Find("_UI");
    Image UIimage = UIfolder.transform.Find("HotspotUI/Panel/KeyIcon").GetComponent<Image>();

    because the specific Unity UI prefabs only get added at runtime, and you can't Find them when they're inactive, so I started on the _UI folder and then drill down to whatever element I need. It's pretty cool you can use the / slashes for that.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.