Loop Sound Based on Distance
Hiya!
I'm trying to create a "proximity sensor" that beeps faster the closer two GameObjects get to each other, but I'm having trouble figuring out what logic would be best for this.
This is my current code, which I'm pretty sure is not the best way to go about it:
dist = Vector3.Distance(beast.transform.position, transform.position);
delay = dist / 60;
if (timestamp == Time.time)
{
proxBeep.Play();
timestamp = Time.time + delay;
}
From what I can tell in the debug log, Time.time simply isn't logging at the same interval timestamp is set to (i.e. timestamp = 2.162 while Time.time goes from 2.161 to 2.163 in the next frame). What's the best way to handle this?
EDIT: Nevermind, I was being stupid. I changed if (timestamp == Time.time) to if (timestamp <= Time.time) and it worked perfectly.
Your answer
Follow this Question
Related Questions
is it possible to reset Time.time 1 Answer
Load scene after time 1 Answer
Clock doesn't stop when reaches 0.0. Can you help me with this. 1 Answer
How is it possible to verify values and is they are correct activate objects ? 0 Answers
I need my timer to only start after it hits a trigger. Please help! 0 Answers