Hi!
I need a special type of hotpot.
I already have a NPC Talk to type, that just shows the cursor and the name of the character, but now I need a hotspot that pops up a "info" graphic, like a small flag, when you hover over a variety of objects.
1. Can a hotspot display a diferent type of text box depending on what it is?
For example can hovering over a crate pop up a box that says "Crate with farm equipment" and a short sentance. Seems more like a menu to me?
2. As I have a lot of different objects to rollover, I wonder if I can use paramenters here (Not having used them before) so I make ONE menu "flag" and fill out different information per item?
thanks
Mark
Comments
You can create a Menu with an Appear type set to On Hotspot, so that it will display when you mouse-over (no need to click). Inside that menu, create a Label to store your info/description.
This is the tricky part: you'll then have to write a custom Action that alters the description based on the Hotspot. This, again, is necessary because this is to work with mouse-overs. However, it should be quite simple. Essentially, you want to attach a Constant ID number to your Hotspots (since this Action will be placed in an ActionList asset, so that it is scene-independent), and then have your Action read the "mouse over" Hotspot's ID and set the description accordingly.
Something like this might go in your Action's Run function: (Where "InfoMenu" and "InfoLabel" are the names of your menu/label respectively, and 123 is an example ConstantID number). More on custom Actions can be found here, as well as in the manual. You'd then place this Action inside an ActionList that's set to run when your Menu turns on.
I have one more question, because I did find the Appear Type, and tried setting it to On Hotspot. and yes it DID work as I wanted. However, it would pop up for every hotspot, including NPCs in additin to the previously defined "Hotspot" menu.
Will your script, due to the constant ID and the dynamic labels the script provide effectively weed out these "normal" Hotspot" labels?
Ive never done any custome actions before, is this (above) the whole thing? Or just aprt of an actin (I mention cos you said "in your Action's Run function" which suggests to me its an excerpt)
if (found == 123)
{
// do something
}
else
{
PlayerMenus.GetMenuWithName ("InfoName").TurnOff (true);
}
Im just getting round to actually doing this now, A few question.
if (!isRunning)
{
isRunning = true;
return defaultPauseTime;
}
else
{
isRunning = false;
return 0f;
}
To be honest I dont quite understand what you mean that bit to do. "ou should be able to add something at the end that turns the menu off if there's nothing to show" ... doesnt the menu turn off by default, its on rollover right?, so roll off = no menu?
Also, how are both these scripts going to "find" the constant ID (the 123 in the scripts). Do I have to add the constant ID to the menu then whatevr adventure creator gives it as an ID, I thin come into this code and "hard-code" it in?
Thats fine, just need to know...
Ill be trying this now anyway, so I may "stumble upon" the answer anyway...
Thanks for all your help... Hope you notice that my posts are becoming slightly less frequent? This is a good thing!
Other questions still relevant
Heres the complete code as I have it now.
{
/* MArk Code!!!
*/
string description = "";
Hotspot activeHotspot = AC.KickStarter.playerInteraction.GetActiveHotspot ();
if (activeHotspot != null && activeHotspot.GetComponent ())
{
int foundID = activeHotspot.GetComponent ().constantID;
if (foundID == 123)
{
description = "Crate with farm equipment";
}
MenuElement myElement = PlayerMenus.GetElementWithName ("InfoMenu", "InfoLabel");
MenuLabel myLabel = (MenuLabel) myElement;
myLabel.label = description;
}
/*
* This function is called when the action is performed.
*
* The float to return is the time that the game
* should wait before moving on to the next action.
* Return 0f to make the action instantenous.
*
* For actions that take longer than one frame,
* you can return "defaultPauseTime" to make the game
* re-run this function a short time later. You can
* use the isRunning boolean to check if the action is
* being run for the first time, eg:
*/
/*
if (!isRunning)
{
isRunning = true;
return defaultPauseTime;
}
else
{
isRunning = false;
return 0f;
}
*/
}
Assets/MyCustomActions/ActionHotspotPopUp.cs(44,55): error CS1026: Unexpected symbol `;', expecting `)'
Assets/MyCustomActions/ActionHotspotPopUp.cs(44,60): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
You're correct to comment out the whole block of code that was already within Run () (in fact you're better off deleting it), but you need to replace it with a zero float return. End the function with:
return 0f;
Doing it again meant that this time (deleting rather than commentin) gave slightly different line numbers:
Assets/MyCustomActions/ActionHotspotPopUp.cs(42,60): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
in the meantime... player broken.. no cursor moving... mark sad... head hurts...see new thread...
OK I removed the amps and so I still get one error:
Assets/MyCustomActions/ActionHotspotPopUp.cs(38,39): error CS0161: `AC.ActionHotspotPopUp.Run()': not all code paths return a value
Checking the "Actions" Tab in the editor I realised that your instructions to put this is a MyCustomActions foder are not completely complete, as I need to set the location of the customs actions folder, so I did.. then this appeared..
The placement in the editor will depend on your category and title fields - you've currently got this as Category.Custom and "Template" (the default values), which will mean the Action is listed as Custom: Template.
If not, try replacing "Action" on line 23 with "AC.Action". The only other thing I can think of is that there's another class called Action in your project that Unity's getting confused with.
> ...Well Ill get that far and see what happens...
Above I took it to mean that the MENU InfoMenu would contain this action on the action list when turn on slot.
But then, where do I actually add the separate descriptions for all the items? I get that there should be space for the text and the constant ID number (Are there public variables I need to add?) But even so, If the script is added at that level, then I would only get that instance of the actin to add one description?
I do hope you didn't misunderstand my needs?
Thing is, that I want a different text to pop up on rollover on all these separate objects.
Now If your idea was to add the action to each hotspot,then I would understand, cos then each hotspot would sent its description text to the menu, that would populate when rolled over.
The sample code is an example: it checks if the Constant ID number on the current Hotspot is 123, and sets the description label if it is. You'd have to change that number, and add other "if" clauses to check for other Hotspots - no need to add any more public variables.