Ads keep us online. Without them, we wouldn't exist. We don't have paywalls or sell mods - we never will. But every month we have large bills and running ads is our only way to cover them. Please consider unblocking us. Thank you from GameBanana <3

How to make random events (UPDATED)

A Tutorial for Baldi's Basics

No ads for members. Membership is 100% free. Sign up!
hello! Its had been time 4 me to update the random event tutorial. So hear it is

1. In the GameControllerScript put all the code in , also make sure you're using the System.Collections namespace

2. Make these variables:

public float eventTimer:
public float eventCooldown;
public bool eventStarted;
public string[] eventText
{
    "Put your event texts here, seperate them with commas to also"
};
private int eventChance;
public AudioClip eventBall;
public Text hudText;
public Image hudImage;
3. Make 2 IEnumerators called "StartEvent" & "StopEvent"

4. Copy this code in the update method

if (this.eventCooldown > 0f)
{
     this.eventCooldown -= Time.deltaTime;
}
else
{
    if (!this.eventStarted)
    {
         StartCoroutine(this.StartEvent());
    }
if (this.eventTimer> 0f)
{
     this.eventTimer -= Time.deltaTime;
}
else
{
    if (this.eventStarted)
     {
          StartCoroutine(this.StopEvent());
     }
5. In the StartEvent IEnumerator put this

this.eventStarted = true;
this.audioDevice.PlayOneShot(this.eventBell);
this.eventChance = Mathf.RoundToInt(0f, [# of events - 1]);
yield return new WaitForSeconds(3f);
this.hudText.text = this.eventTexts[this.eventChance];
this.hudImage.gameObject.SetActive(true);
if (this.eventChance == 0)
{

}
if (this.eventChance == 1)
{

}
this.eventTimer = UnityEngine.Random.Range(40f, 60f);
yield return new WaitForSeconds(3f);
this.hudImage.gameObject.SetActive(false);
yield break;
Make sure the hudText variable is parented to the hudImage variable in Unity;

6. In the StopEvent IEnumerator put this

this.eventStarted = false:
if (this.eventChance == 0)
{

}
if (this.eventChance == 1)
{

}
this.eventCooldown = UnityEngine.Random.Range(60f, 75f);
yield break;

DONE
Sign up to access this!

Embed

Share banner
Image URL
HTML embed code
BB embed code
Markdown embed code

Credits

Key Authors
RealT5mpler
RealT5mpler Joined 11mo ago
Offline
507 points Ranked 46918th
16 medals 4 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • Submitted 15 Tutorials Medal icon
  • 50 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
creator of method

Submitter

RealT5mpler avatar
RealT5mpler Joined 11mo ago
Not on right ok
507 points Ranked 46918th
16 medals 4 rare
  • Returned 1000 times Medal icon
  • 25 posts awarded Exemplary Feedback Medal icon
  • Submitted 15 Tutorials Medal icon
  • 50 posts awarded Exemplary Feedback Medal icon
  • One month a member Medal icon
  • Returned 100 times Medal icon
RealT5mpler
Creator
Sign up to access this!
Sign up to access this!
Sign up to access this!

Game

Sign up to access this!

Category

Details

Difficulty Level
Intermediate

Attributes

Share

  • Share on Reddit
  • Share on Twitter
  • Share on Facebook
  • 1
  • 696
  • 5
  • 2mo
  • 2mo

More from Submitter

WiPs by Submitter

More Other/Misc Tutorials