- Home /
Problem is not reproducible or outdated
Change texture of RawImage
Hello. I have an issue that has been bugging me for a while now. First, what I want to do: We want to change the picture of one RawImage component depending on what map is picked from a Dropdown menu that is called MapSelect which has options on it. I have tried everything that I can to change the image on MapPicture including trying to change its sprite texture with if (MapSelect.GetComponent().value == 0) { MapPicture.GetComponent().sprite = RandomPicture; } (if they haven't selected anything yet) this gave me an error so I tried this paired with a RawImage on the MapPicture GameObject instead of an Image property (yes, I did have the picture as a Sprite 2D and UI) and I declared the MapPicture as a RawImage and I set the RandomPicture as a Texture paired with this line of code: if (MapSelect.GetComponent().value == 0) { MapPicture.GetComponent().texture = RandomPicture; } and it doesn't give me an error. I think it might just be the way I'm setting up the if statement that is checking the value of MapSelect because I had previously put a print() statement within these and it didn't even run. I just have no idea what is going wrong. Thank you for the help.
What's the first error please? What type is the RandomPicture from the first run?
@hexagonius I believe it was a gameObject because that's the first thing I had in $$anonymous$$d. I it ad to have been "Cannot convert sprite to gameObject" or something of that sort.
Answer by IgorSimovic · Mar 28, 2018 at 01:19 PM
This works for me:
Convert texture to appropriate derived class and call Apply method
public RawImage rawImage;
rawImage.texture = ScreenCapture.CaptureScreenshotAsTexture();
(rawImage.texture as Texture2D).Apply();
Answer by Sneakyshot4012 · May 13, 2018 at 07:58 PM
@IgorSimovic I just tried doing it this way and was getting an error on it so I looked at the documentation and in the most recent version of Unity this was removed. Do you have any other way of solving it perhaps? Thank you.
Currently i don't have installed most recent version of Unity so i don't know about that problem. If i find out something in the future i will post it here...
Follow this Question
Related Questions
Detect small targets with Vuforia 0 Answers
How Can I load Different Prefab on Combobox Change? 0 Answers
How to change colors in unity using photon? 0 Answers
Loading user custom image. 2 Answers
Multiple Cars not working 1 Answer