This is in Unity 2018.4.20f LTS. I have a lot of 3d gameobjects that I’m storing in a list. I have searched around but can’t find a way to do it. Right now I have a panel and a bunch of white box images as placeholders. When I pick up an object a white box pops up on my canvas panel.
What I would like to know is there a way to grab an image and display it in place of the white place holder image based on the gameobject’s tag? Like if it is tagged hammer and I have a hammer image display that image?
If so could someone point me in the right direction on how I would accomplish this?
When you pick up the object something happens, right? like the object disappears from the world and is in your hand or something? How do you pick up the object? In my game , if I am within the triggerzone of the object and I want to gather it, I press “E” key to pick it up. The code on that object telling it to disappear from the world ( as I now have it in my inventory) also tells the Raw Image I have on the canvas to be enabled so that icon of the object visible on my HUD. Same for what weapon I am using, how many grenades I have etc. may not be the best way to go but it works for me. The images are all there just invisible until activated.
Hey, you could do something like this. Just drag an Image from you’re assets to the “my_image” field, or set it via code. Hope this leads you in the right direction. And dont forget to add the right tag to your gameObjects and replace it in the script.
public Texture2D my_image;
public List<GameObject> my_gameobjects = new List<GameObject>();
private void Start()
{
for (int i = 0; i < my_gameobjects.Count; i++)
{
if (my_gameobjects*.tag == "place_tag_here")*
{
my_gameobjects*.GetComponent().material.mainTexture = my_image;
_}_
_}_
_}*_