Forum rules - please read before posting.

Hooking into Adventure Creators Raycast with custom scripts

Hey Chris/everyone

I have a few scripts that use

if (Input.GetButtonDown("Fire1"))

or

void OnMouseDown()

Which means when you click on the object anywhere in the room (while first person) it will trigger the script. However I want it to only trigger when it's within AC's raycast limits I have set for Hotspots.

EG

I have a OnMouseDown() script on a mug. This script makes it jump into the air. However I only want it to trigger when you get close enough that the AC hotspot triggers the UI "mug". At the moment you can click on it and it will trigger wherever you are in the room.

Ideal world It would be great something like

if AC.hotspotactivated
{
whatever
}

My only two solutions at the moment is to call the script via an action list using the hotspot component

OR

Set up separate raycast within the script

Both of these would probably work, but a little convoluted.

If you need any more info feel free to ask.

Cheers
Jacob

Comments

  • edited January 2021

    To get an API reference for any Manager field, right-click on the field's label. In the case of the Settings Manager's Hotspot ray length field, it's:

    AC.KickStarter.settingsManager.hotspotRaycastLength
    

    Plugging that into your Raycast's distance parameter would sync it up with AC's raycasting.

    However, if you still allow for regular interacting with Hotspots due to clicks, you can alternatively hook into the OnHotspotInteract custom event to trigger custom code when a given Hotspot is interacted with.

    Here's an example script. Attach it to a Hotspot, and it will print a Debug statement whenever that particular Hotspot is interacted with:

    using UnityEngine;
    using AC;
    
    public class HotspotEventExample : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotInteract += OnHotspotInteract; }
        private void OnDisable () { EventManager.OnHotspotInteract -= OnHotspotInteract; }
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspot == GetComponent <Hotspot>())
            {
                Debug.Log ("Player interacted with: " + hotspot, hotspot);
            }
        }
    
    }
    
  • Legend thank you, will test this out soon.

  • Works a treat, thank you!

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.