- Home /
Display sprite where clicked on screen.
I'm creating a 3D game and would like to display a sprite on screen (2D aspect) on where you click kind of like how runescape displays a yellow cross where you click on the screen.
Thanks!
A screenshot of what you want might be more helpful as many may have no clue of the cross you are referring to. As for the image, do you want to display something when you touch the screen, or do you want something that you can touch once it is displayed? Or do you want something like an image to appear over a soldier/npc that you can click?
Either way, those can be done with the UI introduced with Unity 4.6. But it's not something that someone can just tell you "do this", you may want to take a look at http://unity3d.com/learn/tutorials/modules/beginner/ui
https://www.youtube.com/watch?v=P0wBWC687BY
It's very easy to see what I mean in that video, when the player clicks on objects a red cross appears and when a player clicks on the ground a yellow cross appears.
You seem to have some pathfinding implemented, why not instantiate the sprite at the end of the path ins$$anonymous$$d of where the mouse was clicked?
That's indeed what I'm currently doing but not exactly what I want, hence I'm here asking for a solution.
Answer by komodor · May 28, 2015 at 03:49 PM
http://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
give it mouse coordinates (http://docs.unity3d.com/ScriptReference/Input-mousePosition.html) and you get world position of them, there is only one tricky thing, the mouse doesn't have Z so you need to change Z before you give the coords to ScreenToWorldPoint
I'm sorry! I've been busy the past few days I'll look into this now thank you very much for your answer!
Your answer
Follow this Question
Related Questions
Mouse Click Based Movement/Actions & 2D Sprite Rotation in 3D Space 0 Answers
Rotating a sprite distorts it? 0 Answers
Drag and Drop w/ Snapping 0 Answers
Can't shoot towards mouse click point 0 Answers