Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reset Timer on Trigger?

Discussion in 'Scripting' started by Juliiaan, Aug 25, 2021.

Thread Status:
Not open for further replies.
  1. Juliiaan

    Juliiaan

    Joined:
    Jul 26, 2020
    Posts:
    4
    Reset Timer on Trigger?

    Hi there, i have a Problem. I wan‘t to do it so, that You have a let‘s say sanity and it get‘s higher the longer you stay in the house. The lower the sanity get‘s the crazier you get. But if you get into a seperate room like a safe are, your sanity increases slowly. The problem is i don‘t know how to do it.

    Help is Greatly appreciated!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,758
  3. Juliiaan

    Juliiaan

    Joined:
    Jul 26, 2020
    Posts:
    4
    That does not really help my problem. I want that it over time SLOWLY decreases and if you are standing in a trigger it'll SLOWLY increase over time.
     
  4. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    there is many ways to achieve this.

    if your collider is in the room that raises sanity, you can use OnCollisionStay
    Code (CSharp):
    1. private void OnCollisionStay(Collision collision)
    2.     {
    3.         sanity += amount;
    4.     }
    or using a boolean "
    isInRoom
    " for something like
    Code (CSharp):
    1.  
    2. private void FixedUpdate()
    3.     {
    4.         if (isInRoom)
    5.             sanity += amount;
    6.         else
    7.             sanity -= amount;
    8.     }
    9. private void OnCollisionEnter(Collision collision)
    10.     {
    11.         isInRoom = true;
    12.     }
    13.     private void OnCollisionExit(Collision collision)
    14.     {
    15.         isInRoom = false;
    16.     }
    17.  
    now that's fast-done you should check for > 0 and things like that, but you get the idea.
     
  5. Juliiaan

    Juliiaan

    Joined:
    Jul 26, 2020
    Posts:
    4
    Thanks!
     
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,968
    Do NOT delete the contents of posts, it makes the thread unreadable and is completely against the point of this forum. This forum exists as a support reference for everyone, not a just place to help you. The answers are here for future users benefit from the efforts that people kindly put into helping you. Deleting posts like this against the rules, rude to future users and rude to those who helped.

    The post has been reverted and thread closed.
     
    hippocoder likes this.
Thread Status:
Not open for further replies.