I was wondering how I can draw a texture over a game object.
My situation is:
In my 2d game, I’ve got a trigger zone and when you pass into it you can use a button to activate something. But I want to spawn an arrow over it when the player is inside.
I know how to do the trigger stuff, but I don’t know how to spawn my arrow texture (or create a new gameobject??) over it.
Can someone helps me?
There are usually two ways:
“a decal”: you create a new polygon with a transparent texture.
“decal shader”: or you use a decal shader to draw one texture onto another.
- Create a plane. You can use the build-in plane or you can use the CreatePlane editor script.
- Create a material for the plane using your arrow texture
- Position the plane in the scene at the location and size you want. Note planes are one-sided.
- You can show/hide the plane using the renderer.enabled flag for the plane.
It is difficult for me to visualize what you are doing and why you wrote “not on the screen” given this is a 2D game. It is possible to use “screen” methods of displaying graphics like GUI.DrawTexture or GUITexture and also position that graphic so that it tracks an object in the scene. You could also have two textures for your button, one with the arrow and one without and change them by changing the mainTexture. Or use a shader that allows you to show the second image based on a blend setting.