How can I make an object clone in the time that I indicate it to appear?
Hello everyone!
I'm creating a game for a project and I'm a bit stuck on this part. I've been looking for information on how to instantiate objects (or clones of an object) but most of the code found is to clone them randomly and at a random time (or as in this case, according to the bpm of the music).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts
{
public class Spawner : MonoBehaviour
{
public GameObject[] cubes;
public Transform[] points;
public float beat;
private float timer;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (timer > beat)
{
GameObject cube = Instantiate(cubes[Random.Range(0, 2)], points[Random.Range(0, 2)]);
cube.transform.localPosition = Vector3.zero;
timer -= beat;
}
timer += Time.deltaTime;
}
}
}
This code is the closest thing to what I intend to do (a VR game of the Beat Saber style but boxing). The problem is that the result is that many boxes appear to be hit in a very time interval (the person who plays it can get tired in the first minute). My intention is that the boxes appear and are hit to the sound of the music, so at least I want to control the moment they appear and thus give the person who plays it some time to rest at a time when the music is calm . In other words, it's "ordering" the box to appear at 00:45 second.
If you have any suggestions for this project, please don't hesitate to tell me.
Your answer

Follow this Question
Related Questions
Make a collision check when spawning with Instantiate 1 Answer
Unity Photon Next Step? 0 Answers
Spawning prefabs randomly within a rectangle 1 Answer
javascript to c# convert 2 Answers
Unity Networking: Client spawning and controlling objects 1 Answer