Forum rules - please read before posting.

Hotspot Action Type Settings

Hi,
I am trying to use hotspot as a food object where you can pick up and eat and restore your hunger bar. My understanding is I should manipulate the hotspot action type settings?
What should the hotspot action type settings be? In the drop down menu of hotspot I see it is attached to an interaction script. - Should I be changing something in the script to make the object do something I want to do? ie. restore hunger value and make food item disappear.
Right now I have a player attached to a stats scripts below.
public class PlayerStats : MonoBehaviour
{

public float health = 100;
public float hunger = 100;
public float hygine = 100;

public float deathRate;
public float hungerRate;
public float hygineRate;

public Slider HealthBar;
public Slider HungerBar;
public Slider HygineBar;

public static PlayerStats Instance;

private void Start()
{
    GameObject.DontDestroyOnLoad(this.gameObject);
}
// Update is called once per frame
void Update()
{
    GameObject.DontDestroyOnLoad(this.gameObject);
    /*stats bar*/
    HealthBar.value = health;
    HungerBar.value = hunger;
    HygineBar.value = hygine;
    hunger = hunger - (hungerRate * Time.deltaTime);
    hygine = hygine - (hygineRate * Time.deltaTime);

    if (health <= 0)
    {
        health = 0;
        Debug.Log("Dead");
    }
    if (hunger <= 0 || hygine <= 0)
    {
        health = health - (deathRate * Time.deltaTime);
    }
    if (hunger <= 0)
    {
        hunger = 0;
    }
    if (hygine <= 0)
    {
        hygine = 0;
    }

    //set max value to 100
    if (health >= 100)
    {
        health = 100;
    }
    if (hunger >= 100)
    {
        hunger = 100;
    }
    if (hygine >= 100)
    {
        hygine = 100;
    }
}

}

Comments

  • After doing more research I found out that you can create stats using global variable in AC's manager. So I've created a new variable called 'hunger' and set it to float but I'm completely lost on what I should do next.

  • edited May 2021

    There's a few approaches you can take, depending on preference.

    If you want to do without AC Global Variables, and just stick to your original script, you can write a custom Action that updates your own script's hunger value.

    For example, here's a "Player: Raise stats" Action that lets you choose how much to raise hunger by:

    https://pasteall.org/bwjJ

    It is generally easier to work with AC Global Variables instead, though. If you move your various stats (hunger, health etc), you can use AC's Variable Actions to both set and check their values in your ActionLists, and also map them to Menu elements such as sliders or labels (see this tutorial "this tutorial") for more on this).

    It's also possible to read and update AC Global variable values through script, by referencing either the variable's name or ID number (the number to the left of its name in the Variables Manager). If you want to replace your PlayerStats health/hunger/hygine variables with AC Global Variables, you can still update their values / map them to Sliders in your script:

    AC.GVar hungerVariable = AC.GlobalVariables.GetVariable ("Hunger");
    hungerVariable.FloatValue = Mathf.Clamp (hungerVariable.FloatValue, 0, 100);
    HungerBar.value = hungerVariable.FloatValue;
    

    For more details on manipulating variables through script, see the Manual's "Variable scripting" chapter, or the front page of the Scripting Guide.

  • Thanks Chris! Say if I want the hunger value to decrease with time and I have something like this: hunger -= time.Deltatime * hunger rate
    Where should I be placing this line of code? Can I do that inside AC manager?

  • edited May 2021

    You can update an AC variable in the same way you would a regular script variable. To do something every frame, you'll want to make use of an Update function:

    void Update ()
    {
        AC.GVar hungerVariable = AC.GlobalVariables.GetVariable ("Hunger");
        float hunger = hungerVariable.FloatValue;
        hunger -= time.deltaTime * hungerRate;
        hunger = Mathf.Clamp (hunger, 0, 100);
        hungerVariable.FloatValue = hunger;
    }
    
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.