Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 27, 2020 at 09:02 PM by withlovegiftgiver for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by withlovegiftgiver · Aug 12, 2020 at 07:29 PM · eventdamagerepeatrain

Making a repeating event that detects if you are in the rain?

I want to write a script (or multiple scripts) that randomly selects a time for an event called “rain”. When the event starts, a message will display on the corner of your screen warning you that the rain is coming. It will then start a timer, the duration will be randomly selected between 10 and 30 seconds. The timer will not be displayed. Once time is up, the rain comes down. Whenever you step into the rain you take 10 damage per second that you are in the rain. If you step out of the rain, the damage stops. The rain lasts for a randomized time between 1 to five minutes. When the rain stops, a message appears letting you know that it is safe to step out. The event then ends and will restart in half an hour to two hours.

I currently know how to use box colliders to apply damage per second, and have set up a health bar. I'm wondering if it's possible to still use box colliders to define which areas are in the rain and which are not, for example if you stand under a roof you are not in the rain, therefore you should not take damage.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

  • Sort: 
avatar image
0

Answer by Llama_w_2Ls · Aug 12, 2020 at 07:48 PM

You could also shoot a raycast directly upwards, and if it collides with anything, it means that there is a ceiling, else, youre out in the open.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Aviryx · Aug 12, 2020 at 08:16 PM

This is a pretty interesting idea but not sure how hard it might be to implement. The issues I see are that you really don't want to be "always" checking for a rain event. You would want to kickstart it yourself to have more control and use less resources.


This might point you in the right direction. You could still use box colliders and just check for when the player enters/exits a trigger area. Or... you could use layers. if your terrain/outside stuff is only specific layers you could raycast whatever is underneath the player, get the layer and apply damage if they are outside.


 public class RainManager : Monobehaviour
 {
     // store a reference to the RainEvent script
     public RainEvent rainEvent;

     void Start()
     {
         // when the game first begins we need to specify a time until the "first" rain event.
         // so check if the time until the next event is 0, if so, start the first countdown.
         if (rainEvent.timeUntilNextRainEvent == 0)
         {
             rainEvent.StartRainEventCountdown();
         }
     }
 }

 public class RainEvent : Monobehaviour
 {
     public string warningMessage = "Rain Incoming! Get To Da Choppa!";
     public string eventOverMessage = "it has stopped raining.";

     public bool isRaining;

     public int minimumTimeUntilNextRainEvent;
     public int maximumTimeUntilNextRainEvent;

     public int timeUntilNextRainEvent;

     public int minimumRainDuration;
     public int maximumRainDuration;

     public void StartRainEventCountdown()
     {
         // store how long until the next rain event in minutes
         timeUntilNextRainEvent = Random.Range(minimumTimeUntilNextRainEvent, maximumTimeUntilNextRainEvent)

         countdownStarted = true;

         StartCoroutine(Countdown());
     }

     private void StartRain()
     {
         isRaining = true;

         int rainDuration = Random.Range(minimumRainDuration, maximumRainDuration)
     }

     private void StopRain()
     {
         //
     }

     private IEnumerator Countdown()
     {
         while (timeUntilNextRainEvent > 0)
         {
             timeUntilNextRainEvent -= 1;
             yield return new WaitForSeconds(60);
         }

         StartRain();
     }

 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by withlovegiftgiver · Aug 13, 2020 at 05:58 AM

Ok, thanks to both of you for your input, I've managed to make it work as it should except for the fact that it doesn't loop, so this event can basically only happen once. Here is my code:

 {
     timeUntilNextRainEvent = Random.Range(minimumTimeUntilNextRainEvent, maximumTimeUntilNextRainEvent);
     countdownStarted = true;
     StartCoroutine(Countdown());
 }
 private void StartRain()
 {
     isRaining = true;
     int RainDuration = Random.Range(minimumRainDuration, maximumRainDuration);
     StartCoroutine(Duration());
 }
 private void StopRain()
 {
     isRaining = false;
 }
 private IEnumerator Countdown()
 {
     while (timeUntilNextRainEvent > 0)
     {
         timeUntilNextRainEvent -= 1;
         yield return new WaitForSeconds(5);
     }
     StartRain();
 }
 private IEnumerator Duration()
 {
     while (RainDuration > 0)
     {
         RainDuration -= 1;
         yield return new WaitForSeconds(5);
     }
     StopRain();
 }

Is there a way to loop this every hour without changing the code too much?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

136 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to define the number of times of an event? 1 Answer

Help to trigger a rain event 1 Answer

Any way to key JUST keydown and JUST keyup events? 6 Answers

How to repeat damage 1 Answer

How can I make a SerializedProperty UnityEvent persist within a CustomInspector editing a ScriptableObject? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges