Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question How to make something activate at any time but only execute at certain intervals?

Discussion in 'Scripting' started by jbsgroup, Feb 10, 2024.

  1. jbsgroup

    jbsgroup

    Joined:
    Aug 27, 2022
    Posts:
    6
    I'm making a rhythm based game and for part of it, the player is able to spawn note clusters in a guitar hero-like minigame. They need to be able to activate it at any time, but the notes don't spawn until the beat. I have the code for everything working (spawning the clusters, hitting them, etc), but I need them to spawn on-beat to have the correct timing. I already have a variable called beatTempo that I use to calculate the beats per second, which I feel could be used to easily, and is probably best as I need this to repeat an indeterminate amount of time (there will be looping music, so the player will be doing the minigame until they win). But, I'm an amateur with unity and I'm not sure how to do that. Any advice is appreciated
     
    Last edited: Feb 10, 2024
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,649
    If you command something NOW and you want it to happen later, one pattern is to use a Coroutine that watches for when the correct time is up and then does the thing you want at that later time.

    Storing what you want done in a delegate (aka, System.Action variable) is the usual approach here.

    Otherwise, rather than hoping for some text answer to what is an extremely timing- and art-dependent game, you'll probably do a lot better working through at least one, maybe two or even three rhythm action tutorials.

    I recommend making a fresh empty project to work through some tutorials and learn the essentials necessary: spawning a note, judging a player input, etc.

    Same goes for just about any twitch-action game... all the concepts involved in a bullet hell space shooter are the same ideas used in a rhythm-action game: counters, timers, velocities, events, etc.