Forum rules - please read before posting.

Cursor Animation on Click Floor/Hotspot/Anywhere

edited October 2023 in Technical Q&A

Hi there,
Hope you all doing good.

I want my cursor have such a behaviour like this video.
When I click on navmesh, some outline circles animation plays.
When I click on hotpost (despite cursor change which still need to happen), only one outline circle animation plays.
When I click on non navmesh area, only a filled circle animation plays. (this one is not really mandatory, just curious)

If the above ones are complicated, is this possible? whenever I click anywhere no matter if it is hotspot or nav/etc, just some outline circles animation plays. I just want to have this behaviour, it gives more clarity or feeling of something happened.

Thaaanks

Comments

  • You'd need to be familiar with Unity's Animation system, but with the aid of a custom Action, it's possible.

    The circle animation(s) would be a prefab that gets spawned in when you click, and which then plays a different animation according to what you clicked on.

    1. Add an empty to the scene and attach an Animator. Use Unity's Animation tools to create 3 animations - one for when clicking on the NavMesh, another for when clicking on a Hotspot, and another for when clicking elsewhere. Make this last one the default.
    2. For the NavMesh and Hotspot animations, create Trigger parameters that cause these animations to play. Name them "NavMesh" and "Hotspot" respectivly.
    3. Make this object a prefab, and remove from the scene.
    4. Go to your Project setting's Input manager, and create a new Input named Click. Set its Positive button to mouse 0.
    5. Go to AC's Active Inputs window (in the top toolbar) and create a new Active Input. Set its Input button to Click, and assign an ActionList asset in its ActionList when trigger field.
    6. Create a new folder in your Project window, and copy/paste the code below into a C# file named ActionClickAnim. In the Actions Manager, point to this folder from the "Custom Action scripts" panel to install it as a new Custom: Click animation Action.
    7. Go to the ActionList created in step 5 and add this new Action to it. Assign the prefab created in step 1, and make sure the Trigger names match.

    That ought to do it!

  • using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionClickAnim : Action
        {
    
            public GameObject clickPrefab;
            public string onHotspotTrigger = "Hotspot";
            public string onNavMeshTrigger = "NavMesh";
            private GameObject spawnedClickOb;
            public float lifeTime = 4f;
    
            public override ActionCategory Category { get { return ActionCategory.Custom; }}
            public override string Title { get { return "Click animation"; }}
    
            public override float Run ()
            {
                if (clickPrefab == null || KickStarter.playerMenus.IsMouseOverMenu ())
                {
                    return 0f;
                }
    
                Vector3 mouseScreenPosition = KickStarter.playerInput.GetMousePosition ();
                Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint (mouseScreenPosition);
                mouseWorldPosition.z = KickStarter.player.transform.position.z;
    
                spawnedClickOb = Instantiate (clickPrefab, mouseWorldPosition, clickPrefab.transform.rotation);
                Destroy (spawnedClickOb, lifeTime);
                Animator _animator = spawnedClickOb.GetComponent<Animator> ();
    
                RaycastHit2D hit = Physics2D.Raycast (mouseWorldPosition, Vector2.zero);
                if (hit != null && hit.collider != null)
                {
                    if (hit.collider.GetComponent<Hotspot> ())
                    {
                        _animator.SetTrigger (onHotspotTrigger);
                    }
                    else if (hit.collider.gameObject.layer == LayerMask.NameToLayer ("NavMesh"))
                    {
                        _animator.SetTrigger (onNavMeshTrigger);
                    }
                }
    
                return 0f;
            }
    
            public override void Skip () { }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                clickPrefab = (GameObject) EditorGUILayout.ObjectField ("Prefab:", clickPrefab, typeof (GameObject), false);
                onHotspotTrigger = EditorGUILayout.TextField ("Hotspot Trigger:", onHotspotTrigger);
                onNavMeshTrigger = EditorGUILayout.TextField ("NavMesh Trigger:", onNavMeshTrigger);
                lifeTime = EditorGUILayout.FloatField ("Lifetime:", lifeTime);
            }
    
            #endif
    
        }
    
    }
    
  • Oh this worked like a charm! B)
    I wanted to take a moment to express my heartfelt gratitude for the outstanding guidance you provided. That was incredibly clear and helpful. <3
    I can attach the Prefab to the wiki if that helps others (anims included) with your explanation. This is kind of a small but nice feature.

  • I'm sure that would be welcome. It might also be a good fit for the Downloads page - I'll give it some thought, thanks for the suggestion.

  • edited October 2023

    Thank you for the best guidance.

    I just added it on wiki, just couldn't to upload my .unitypackage file which already had animations, script, etc which could be skipped to step 7 on wiki. However if I find a good host I will upload it at some point. Or you can download it and take a look if that's good add this to Downloads.

    Once again thaaaanks a lot :)

  • Looks good, thanks.

    I've made a few tweaks to simplify things, and have added this to the Downloads page.

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.