Forum rules - please read before posting.

Animated Cursor on Click During Gameplay

I'd like to have my circle cursor change to an "animated cursor" whenever the user clicks, then back to the circle cursor. I see how to change the cursor this with interactions on hotspots, but I'd like it to happen anywhere the user clicks on the scene. This is mainly because I'm making a touch-screen game and I'd like the user to know where they've tapped the screen.

Any suggestions on how to do this?

Comments

  • Welcome to the community, @sonicjoy.

    Cursor animations can be set to play when hovering over interactive objects, but given the complexity of the different kinds of cursor "modes", and the fact that you're using touch-screen and not a "real" cursor - this is best left to a custom script.

    Try this:

    Paste it into a new C# script named AnimateOnTouch.cs, and attach it to an Image UI component on a UI Canvas in your scene.  The script will position this image at the cursor/touch position, and animate it whenever a touch is made.

    This will be done by invoking a Trigger parameter on an Animator also attached to the Image - so you'll need to add that component, and create an Animator Controller that plays a "click" animation when the named Trigger parameter is invoked.

  • Thank you, Chris! I'm having a lot of fun making a game with Adventure Creator (and learning Unity concurrently!)
  • Does anyone have a working link to this script? The link in the post is no longer working unfortunately.

    I want to play a short animation momentarily each time the player clicks anywhere on the screen and at the click location of the cursor. For example, a small ripple will appear when clicking on water or a puff of dust when clicking on ground.

    Is there any way to achieve this with the AC engine or will I have to use a script like this? Thank you.

  • I'll paste the script below, but since the original post AC has a "Unity UI" option for cursor rendering at the top of the Cursor Manager.

    With this option, the cursor is drawn using Unity UI components, which allow it to be controlled/modified through Animations that can be set to trigger when clicking.

    See the Manual's "Unity UI Cursor rendering" chapter for more details.

    AnimateOnTouch.cs:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using AC;
    
    public class AnimateOnTouch : MonoBehaviour
    {
    
        public Animator _animator;
        public string clickEffectTrigger = "ClickEffect";
        public string clickIconInt = "IconID";
        private RectTransform rectTransform;
    
    
        private void Awake ()
        {
            rectTransform = _animator.GetComponent <RectTransform>();
        }
    
    
        private void Update ()
        {
            rectTransform.position = Input.mousePosition;
    
            if (Input.GetMouseButtonDown (0) && KickStarter.stateHandler.IsInGameplay ())
            {
                Hotspot activeHotspot = KickStarter.playerInteraction.GetActiveHotspot ();
                if (activeHotspot == null)
                {
                    // Clicked on nothing
                    Debug.Log ("Clicked on nothing");
                    PlayAnim (-1);
                }
                else if (activeHotspot.IsSingleInteraction ())
                {
                    // Clicked on single-use Hotspot
                    int iconID = activeHotspot.GetFirstUseIcon ();
                    Debug.Log ("Clicked " + iconID);
                    PlayAnim (iconID);
                }
            }
        }
    
    
        private void PlayAnim (int ID)
        {
            _animator.SetInteger (clickIconInt, ID);
            _animator.SetTrigger (clickEffectTrigger);
        }
    
    }
    
  • Thanks Chris. I don't full understand it yet but I will see if I can work it out.

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.