- Home /
Need help with pressing on a sprite to put another sprite higher in the sorting order
Hi, I'm trying to make a simple prototype on android to explain an idea, but this last part just won't work for me.
I have three sprites.
1 A neutral background, which is static and I don't do anything with.
2 A small drawn sprite of a cat, which I applied a random move script to which makes it move to random locations.
3 A picture of a cat.
The idea is that 3 the picture is behind the background in sorting order, and pops up to the foreground when I press on 2 the drawn sprite. Then I press anywhere and the picture goes back in the sorting order. That last part works, the second doesnt.
Here is the working code for the last part (RandomPatrol is the script for the cat sprite to move around):
And here is the script that doesn't do what I want it to do:
. . .
So I know why it probably doesn't work. The script doesn't reference to the gameobject catpicture I want to move, right? Well if I try to call it with gameObject.Find then the object is defined as a gameObject and can't use the sortingOrder function, because that is a SpriteRenderer function, apparently.
Anyway I have 0 clue of what I'm doing. Ive run out of time and have to write a lot of other things.
Any help would be very very appreciated.