Home>

There are times when music game makers are having trouble implementing it for some time.
When generating a side-by-side note group that presses multiple buttons at the same time, such as pressing four buttons at the same time 1.3 seconds from the start of the song, the script currently in useforUpdate ()Due to the slight difference until the variable is incremented by +1 in the contents, the numbers are exactly the same in the json file for reading, but they shift like a staircase.

Code used
void Update () {
    time = trackon.GetComponent  (). Time;// Time from the start of the song
    if (time>= eei [f]) ​​// Compare with array elements with timing data
    {
        See // num
        GameObject nt;
        switch (rea [f]) ​​// Check the elements of the array with lane information
        {
              case 0:
                  basyo = -2f;
                  break;
              case 1:
                  basyo = -0.25f;
                  break;
              case 2:
                  basyo = 1.5f;
                  break;
              case 3:
                  basyo = 3.23f;
                  break;
              case 4:
                  basyo = 4.98f;
                  break;
              default: default:
                  basyo = 3.6f;
                  break;// Set the notes generation position according to the lane information
        }
        nt = Instantiate (mi, new Vector3 (basyo, 5.7f, -0.2f), Quaternion.identity) as GameObject;
        noteGo.Add (nt);// List
        f + = 1;// Go to the next note
    }
}


Notes are generated by the above writing method, but with this writing method, as mentioned above, it will flow in a staircase shape that is not aligned horizontally. The method of dividing the generation according to the number of lanes remains the same, but it was impossible to check the subsequent notes timing because the intention of simultaneous pressing was not correct because it was done by hand without using the notes editor etc. .. Especially in the case of 3 lanes and 5 lanes, it is especially troublesome, and the situation is that the musical score cannot be recognized properly due to the stepped deviation.

I want to implement

I would like to implement a code that eliminates the generation gap caused by updating the variable f and makes it fall in a horizontal row no matter how many are pressed at the same time.

usage environment
Unity2019.1.5f1 Visual Studio
Postscript
I made a mistake in the explanation about the processing in the source, so I corrected it.
(✕ for ◯ Update ()) 2020.11.20

  • Answer # 1

    Well, it's a problem because only one note is processed when Update is called, isn't it?

    I think it's okay to form a loop and process all the Notes information that must be processed at that time.

  • Answer # 2

    I may have removed it, but I think it's bad to get the time every time in Update.
    Assuming that there are multiple objects to be updated, first get the time once before updating,
    Shouldn't we just update all the objects using that as the reference time?