I have a close up of the surface of a pond and want to play a short sprite animation of a ripple on the surface at the point where I click. Unfortunately, I can't work out how to do this. I can get the ripple to appear every time I click but it always appears in the same place and not at the cursor position.
Any suggestions?
Comments
The mouse position can be read with:
Input.mousePosition
To convert it to a world position, use:
Vector3 worldPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
You can then position the ripple according to that with e.g.:
myRippleGameObject.transform.position = worldPosition;
You can combine the spawning/positioning code with AC to easily limit the region that the ripples appear, e.g. only when clicking on a Hotspot. This is done by using the OnHotspotInteract event - see the "Custom events" chapter of the Manual for more on how they work. This event can be used to check if the player clicked on a Hotspot that represents the pond, and only then spawns the ripple.
using System.Collections;
using AC;
public class PondEvent : MonoBehaviour
{
public Hotspot pondHotspot;
private void OnEnable ()
{
EventManager.OnHotspotInteract += OnClickHotspot;
}
private void OnDisable ()
{
EventManager.OnHotspotInteract -= OnClickHotspot;
}
private void OnClickHotspot (Hotspot hotspot, AC.Button button)
{
if (hotspot == pondHotspot)
{
Debug.Log ("The pond was clicked on!");
}
}
}