Forum rules - please read before posting.

Create Animation At Cursor When Not Clicking On Hotspot

Hi everyone. I am a bit stumped and would appreciate any help with this.

I am using the code below to create an animation at the cursor location when clicking on a Hotspot. For instance, a ripple when clicking on water. The code works well.

However, I want to create a default animation to be played in the same way when no Hotspot is being clicked on. In this case it is a puff of dust to let the player know clicking here does nothing. I have tried modifying the code by adding an Else statement and a few other things but as far as I can tell this code relies on a Hotspot being clicked on.

Is there a simple way for me to achieve what I want? Do Unity or AC have a setting that relates to this. Thank you for any help.

`using UnityEngine;
using AC;

public class ACC : MonoBehaviour
{
public Hotspot hotspot;
public GameObject ACC_GameObject;
public float lifeTime;

private void Awake()
{
    EventManager.OnHotspotInteract += ACC_Appear;
}

public void ACC_Appear(Hotspot hotspot, Button button)
{
    if (hotspot == this.hotspot && button == hotspot.GetFirstUseButton())
    {
        Vector3 worldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        worldPosition.z = hotspot.transform.position.z;
        GameObject go = Instantiate(ACC_GameObject);
        go.transform.position = worldPosition;
        Destroy(go, lifeTime);
    }
}

private void OnDestroy()
{
    EventManager.OnHotspotInteract -= ACC_Appear;
}

}`

Comments

  • There's no AC event for the case that the mouse is clicked over empty space - but you can read Unity's Input.GetMouseButtonDown function for that.

    You can then read the value of AC's GetActiveHotspot and IsMouseOverMenu functions to determine if the mouse was over a Hotspot or Menu at the time:

    void Update ()
    {
        if (Input.GetMouseButtonDown (0))
        {
            if (KickStarter.playerInteraction.GetActiveHotspot () == null &&
                !KickStarter.playerMenus.IsMouseOverMenu ())
            {
                // Clicked over empty space
            }
        }
    }
    
  • Thank you for your quick and helpful response as always, this looks perfect. I tried using a large Hotspot that covered the whole scene but it caused a noticeable performance drop in the larger scenes. This is a far more elegant solution.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.