Forum rules - please read before posting.

Remove Click Marker when Player reaches Destination

Hello there Chris and all the AC group!
So, I've released ENCODYA not even 2 months ago and I'm up for a new game that relies on Adventure Creator!
Something totally different...
This time I'm using a "Click Marker" and I wonder: is it possible to remove it when the Player reaches the destination?
I've a "looped" prefab as click marker (so I'm not relying on the time since spawn). And what I would like is to remove it from the scene when the player reaches the prefab (therefore the destination).
I'm using point-and-click movement system, so there's a path-finding and basically I'd like to write a script to remove the instantiated prefab (click marker) when the Player reaches the end of that path.
I've tried to read the api, but couldn't find a way... (I guess comparing in update player.transform with destionation.transform is not the best... right? I guess there's an event called?)
Any hint is very welcome!

Comments

  • I guess there's an event called?

    Yes - OnCharacterEndPath is what you want:

    void OnEnable () { EventManager.OnCharacterEndPath += OnCharacterEndPath; }
    void OnDisable () { EventManager.OnCharacterEndPath -= OnCharacterEndPath; }
    
    void OnCharacterEndPath (Char character, Paths path)
    {
        if (character == KickStarter.player)
        {
            // Remove the click marker
        }
    }
    

    For a full list of character-related events, see the Manual's "Character scripting" chapter.

  • Awesome, thanks!

  • In addition to removing the click marker when the player reaches his destination, I would also like to remove the marker when player interrupts his movement by clicking on a hotspot instead of the navmesh. How can this be done? It would be great if these two scenarios could be switched on with checkboxes in the settings tab.

    Thanks,
    Jay

  • The OnHotspotInteract event will be fired at the moment the player clicks on a Hotspot.

    Having the marker auto-remove when clicking a Hotspot is a fair suggestion, though. Would you be looking to have the marker re-appear at the Hotspot?

  • No, I am currently only wanting the marker for indicating the destination of the click on the navmesh.

  • Unset the click marker from the Settings Manager and try this script in your scene instead:

    using UnityEngine;
    using AC;
    
    public class NavMeshClickMarker : MonoBehaviour
    {
    
        public GameObject clickPrefab;
        protected GameObject clickPrefabInstance;
    
        private void OnEnable () { EventManager.OnPointAndClick += OnPointAndClick; }
        private void OnDisable () { EventManager.OnPointAndClick -= OnPointAndClick; }
    
        private void OnPointAndClick (Vector3[] pointArray, bool run)
        {
            if (pointArray.Length == 0 || clickPrefab == null) return;
    
            Vector3 clickPosition = pointArray[pointArray.Length - 1];
            if (clickPrefabInstance && clickPrefabInstance.activeSelf)
            {
                Destroy (clickPrefabInstance);
            }
    
            clickPrefabInstance = Instantiate (KickStarter.settingsManager.clickPrefab, clickPosition, Quaternion.identity);
        }
    
    }
    
  • Thanks again for the code snippet. I was getting a type error with the last line of your example. The following code works well for me with a looping particle click marker:

    using UnityEngine;
    using AC;
    
    
    public class NavMeshClickMarker : MonoBehaviour
    {
        public GameObject clickPrefab;
        protected GameObject clickPrefabInstance;
    
    
        private void OnEnable () 
        { 
            EventManager.OnPointAndClick += OnPointAndClick;
            EventManager.OnCharacterEndPath += OnCharacterEndPath; 
        }
    
    
        private void OnDisable () 
        { 
            EventManager.OnPointAndClick -= OnPointAndClick;
            EventManager.OnCharacterEndPath -= OnCharacterEndPath;
        }
    
    
        void OnCharacterEndPath (Char character, Paths path)
        {
            if (character == KickStarter.player)
            {
                // Remove the click marker
                Destroy (clickPrefabInstance);
            }
        }
    
    
        private void OnPointAndClick (Vector3[] pointArray, bool run)
        {
            if (pointArray.Length == 0 || clickPrefab == null) return;
    
            Vector3 clickPosition = pointArray[pointArray.Length - 1];
            if (clickPrefabInstance && clickPrefabInstance.activeSelf)
            {
                Destroy (clickPrefabInstance);
            }
    
            clickPrefabInstance = Instantiate (clickPrefab, clickPosition, Quaternion.identity);
        }
    }
    
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.