Page 2 of 2
Re: Proximity Selector World Space Button
Posted: Fri Jul 10, 2020 4:36 pm
by Tony Li
Hi,
Instead of all that, you could bypass SetCurrentUsable() entirely.
SetCurrentUsable() basically just runs this code:
Code: Select all
currentUsable.OnUseUsable();
currentUsable.gameObject.BroadcastMessage("OnUse", fromTransform, SendMessageOptions.DontRequireReceiver);
You could configure your world space button to send the same message by putting this method in a script on the Usable:
Code: Select all
public void UseMe()
{
GetComponent<Usable>().OnUseUsable();
this.gameObject.BroadcastMessage("OnUse", fromTransform, SendMessageOptions.DontRequireReceiver);
}
Configure the button's OnClick() event to call UseMe().
Re: Proximity Selector World Space Button
Posted: Fri Jul 10, 2020 11:23 pm
by EnigmaFactory
With some fiddling, I got it to work! I had to move the WorldSpaceUsableButton script to the Root Object (Receptionist) from the world space button I had it on so it was by Usable component. Could prolly get around that now, realized originally my inability to find Usable was due to Namespace not being defined.
My next issue was "fromTransform" you put in there. Had to figure out if that referenced the NPC Actor or the Player object (it's the Player!) So I did it as below. Is there a more efficient way to get Player object without doing a Reference? As I don't want to drag Player into each component on each Actor. haha. Trying to optimize the whole procedure of creating new interactables. Incoming lots of questions as I work to dynamically create the Screen Space Interact buttons with different Icons based on type and different interact animations and such
I've bought all your assets, but I'm prolly getting to the point of owing you even more money now.
Code: Select all
namespace PixelCrushers.DialogueSystem
{
public class WorldSpaceUsableButton : MonoBehaviour
{
public void ClickedUseButton()
{
GetComponent<Usable>().OnUseUsable();
this.gameObject.BroadcastMessage("OnUse", GameObject.FindGameObjectWithTag("Player").transform, SendMessageOptions.DontRequireReceiver);
//FindObjectOfType<PixelCrushers.DialogueSystem.ProximitySelector>().UseCurrentSelection();
}
}
}
Re: Proximity Selector World Space Button
Posted: Fri Jul 10, 2020 11:32 pm
by Tony Li
You could use a static variable to track the player GameObject. Example:
Code: Select all
public class PlayerReference : MonoBehaviour // Add to player.
{
public static GameObject player;
void Awake() { player = this; }
}
Then:
Code: Select all
this.gameObject.BroadcastMessage("OnUse", PlayerReference.player, SendMessageOptions.DontRequireReceiver);
For Screen Space interact buttons, you might be able to use the Selector Use Standard UI Elements component. (See DemoScene1 for an example. This component is on the player.) You can assign different UI elements according to tag and/or layer.