# Using Time.time in an if statement?

**URL:** https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718
**Category:** Scripting
**Tags:** Scripting
**Created:** [August 19, 2009, 9:18pm UTC](https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718 "2009-08-19T21:18:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_24038877](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@anon\_24038877](https://discussions.unity.com/u/anon_24038877)
#### Post date: [August 19, 2009, 9:18pm UTC](https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718/1 "2009-08-19T21:18:02Z")

</div>

I’m trying to use the following code to wait for two and a half seconds before playing an audio clip attached to the same GameObject:

```auto
function Update() {
	var PlayTime = 2.5;
	if (Time.time = PlayTime) {
		audio.Play();
	}
}

```

I get the following error:  
(3, 23) BCE0044 expecting ) found ‘=’  
Fixing this error (changing it to (Time.time) = PlayTime )causes another error:  
(3, 24) BCE0043 unexpected token =

Any idea what is wrong? I know I saw Time.time used in a similar way in a scripting reference example.

---

<div class="post-metadata">

### Author: ![Discord](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/discord/32/568561_2.png) [@Discord](https://discussions.unity.com/u/Discord)
#### Post date: [August 19, 2009, 9:20pm UTC](https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718/2 "2009-08-19T21:20:54Z")

</div>

```auto
if (Time.time = PlayTime) {

```

should be `if (Time.time == PlayTime) { `

---

<div class="post-metadata">

### Author: ![Eric5h5](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/eric5h5/32/44225_2.png) [@Eric5h5](https://discussions.unity.com/u/Eric5h5)
#### Post date: [August 19, 2009, 11:16pm UTC](https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718/3 "2009-08-19T23:16:04Z")

</div>

That won’t work anyway, since Time.time will almost certainly never equal exactly 2.5. Don’t use Update at all, use yield WaitForSeconds in Start.

–Eric

---

<div class="post-metadata">

### Author: ![Murcho](https://avatars.discourse-cdn.com/v4/letter/m/e480ec/32.png) [@Murcho](https://discussions.unity.com/u/Murcho)
#### Post date: [August 19, 2009, 11:49pm UTC](https://discussions.unity.com/t/using-time-time-in-an-if-statement/396718/4 "2009-08-19T23:49:33Z")

</div>

I’d suggest the coroutine route as well, however if you don’t feel confident enough to travel down that path yet, you should alter your if test to:

```auto
if (Time.time >= PlayTime) 
{ 
   audio.Play(); 
}

```

You need to be careful though as this will continue to call the play function after this, so using a coroutine with WaitForSeconds will probably be the safer route to go.
