Hello, I currently have objects spawning to the beat of the music. However, when they hit the player’s prompt, they are out of sync because of the time taken to travel from the left to the right of the screen.
The music is coming from the main camera, I was thinking of having 2 separate music tracks. 1 for the player to hear, which is delayed by a couple seconds, and the one that the code listens to to spawn the objects. Would this work? Any ideas how to implement this?
Thanks.
Here is how the beats are listened to/objects are spawned.
public Transform target;
public int minRange;
public bool follow;
//public Light spotlight;
private float speed;
public Rigidbody projectile;
private float cooldown = 0.5f;
public int detail = 250;
public float amplitude = 0.2f;
public float minValue = 1.0f;
void Start () {
}
void Update(){
cooldown -= Time.deltaTime;
float[] info = new float[detail];
AudioListener.GetOutputData(info, 0);
float packagedData = 0.0f;
for(int x = 0; x < info.Length; x++)
{
packagedData += System.Math.Abs(info[x]);
}
if (packagedData/info.Length > 0.2f && cooldown < 0) {
cooldown = Random.Range(1f,1.5f);
Rigidbody clone;
clone = Instantiate (projectile, transform.position, transform.rotation) as Rigidbody; //This seems to create the clone
clone.velocity = transform.TransformDirection(Vector3.forward * 40); //This details the velocity of the projectile
}
}
}