Need a little basic guidance

Tried searching, but don’t really know the buzzwords for what I want to do…

I’m setting up a system where I can “Use” an item like a Campfire by pressing a key. When that happens a UI menu pops up and gives optins as to what you want to do with the Campfire.

I prefer to have just one UI menu which can be called from all instances of Campfire. (this seems most efficient) - but when the button is clicked - how do I let it know which Campfire to affect?

So, looking for a way to designate the “last used” Campfire. Do I set a tag on the GO like “Used” and then return it to normal after I close the menu? Or is there another way to do this.

Thanks!

Looks like you have to learn basic coding.

Setting up variables, accessing other scripts, knowing if you should not destroy an object on new scene load are all things that sound like things you need to know.

//////
As for vairables. they can be static or non. Static means they are global, the exist everywhere and can be called from anywhere by nothing short of a line of code. People tend to use these sparingly since they can clutter up a program. Local variables, can be local to a script, or local to a function. Meaning the whole script can access it, or only inside a single function where it was defined.

//////
If you want a single menu that is acessable always, I would do this. Always, if you load a new level, insure the menu is using DontDestroyOnLoad(menu). This makes sure you only have one menu and it is only loaded once, this can save loading time. This menu could contain static vars. Or regular.

You will want to access other variables from other scripts. So, when you click the button, you need to know which campe fire to affect. So, lets say you press button 1, this affcets campfire 1.

///in your manager (scene/ui/fire...)
var campFire1Active : boolean;
function Update()
{
if(Input.GetButton("1"))
{
campFire1Active = true;
}
}

Now, if you have some other script, say fireScript, which simple manages any single fire, perhaps this fire needs to know if fire 1is active. You could write…

////this is the general script attached to each individual fire. 

///these vars are public to this script. 
///all other fires, have this script as well, in order to access any variable from another fire you must use GetComponent
///this example shows how

var campFireOther :  GameObject; ///this object must be filled by any other campFire
var campFireActive : boolean;///if true, this fire is active
function checkIfCampFireOtherActive()
{
var campFireOtherActive : boolean; ////this will be sued to store the info, if the other fire is active. 

///so, with the campFireOther var, we need to access its campFireScript to ask it questions about itself.
var campFireOtherData : campFireScript; ///define the script name (component) we are looking for. 
campFireOtherData = campFireOther.GetComponent(campFireScript);
var campFireOtherActive : boolean;
campFireOtherActive = campFireOtherData.campFireActive;

////what has happened there is, we defined the component we needed to access. 
///we retrieved to component off of the other fire
///we defined a var that is internal this function, if other camp fire active
///we asked if other camp fire is active.

///now we can do something with that information.

if(campFireOtherActive == true)
doThis();
else if(campFireOtherActive == false)
doThat();
}

To designate which is the last camp fire used, you would want to have each campFireScript (again, a single script, component that is attached to each fire), talk to the scene manager or fireManager, whatever title you find more fitting. By talking to each other I mean, when a fire is turned on, it should pass that info to the manager. The manager will now know, what fire was last used.

///this would also be part of the fire script.

///imagining with a button input you have turned on this fire.
function Update()
{
if(Input.GetButton("fireButton")
turnOnThisFire();
}

function turnOnThisFire()
{
campFireActive = true;

///now we need to access the manager to inform it of the activation of this fire
///normally you should just access the component of the manager at Start() but this will do for now. 
///...reason being that you do not want to use getComponent on the same component over and over. It is a waste of energy.
///but this will do for now.

var fireManager : GameObject;
fireManager = GameObject.Find("fireManager");///normally this should jsut be public, but this will do for now.
var fireManagerData : fireManagerScript;
fireManagerData = fireManager.GetComponent(fireManagerScript);

////now that we have the componet stored and can access it, pass the information that this fire is active. 
var fireIndex : int;///agian this should be public but here is fine for now, each fire has its own index number.
fireManagerData.fireIndexOfLastActiveFire = fireIndex;
///we have just told the manager that this fire of this index is active.
//it now nows the last active fire.

}

Thanks, your last code snippet helped me figure this out. I forgot to mention that the Campfires are prefabs so are not initially fixed in the scene. So having them get a reference to the player and vice versa was more difficult than I had thought.

Great.
Glad I could help.

:)(