The game is top-down 2D with the camera fixed on the player as they move around the map.
We want to have an indicator of where the last touch position was, which seems to mean having the indicator as a prefab, instantiating it on finger press and then transforming it correctly:
Prefabs of UI elements are instantiated as normal using the Instantiate method. When setting the parent of the instantiated UI element, it’s recommended to do it using the Transform.SetParent method with the worldPositionStays parameter set to false.
There are 2 problems that I don’t know how to tackle:
- Drawing the prefab image on the UI.
- Drawing it at the correct position (i.e. directly under the touch position in screen space).
Can anyone provide some C# example code to help achieve this? I have tried using the “Transform.SetParent method” (as advised here) but I’m not having much luck figuring out how to implement it.