This is the entire script, I just want the camera to activate 0.5 seconds after you press the mouse button. How would I go about this?
Note: I know I could make this much more compact but I like it like this. C# please
using UnityEngine;
using System.Collections;
public class Aim_s : MonoBehaviour {
public bool Aim = false;
public GameObject Cam;
float delay = 1;
void Start() { Cam.active = false; }
void Update()
{
if (Input.GetMouseButtonDown(1))
{
Aim = true;
if (Aim == true)
{
Cam.active = true;
}
}
if (Input.GetMouseButtonUp(1))
{
Aim = true;
if (Aim)
{
Cam.active = false;
}
}
}
}
- float timer= float.MaxValue;
- When the user presses the mouse timer = Time.time + .5f (set the timer .5 seconds in the future)
- in Update(){ if(Time.time > timer) activate camera }
- When deactivating: timer = float.MaxValue
Let me know if you want more details. Basically we have a timer and when we click the timer gets set for .5 seconds. Then when Time.time passes the timer we activate the camera.
Thanks, I ended up with this, I finished getting rid of extras as well! Let me know if there is anything I did wrong or could do better.
using UnityEngine;
using System.Collections;
public class Aim_s : MonoBehaviour
{
public bool Aim = false;
public GameObject Cam;
public float timer = float.MaxValue;
void Start() { Cam.active = false; }
void Update()
{
if (Input.GetMouseButtonDown(1))
{
timer = Time.time + .8f;
}
if (Time.time > timer)
{
Cam.active = true;
}
if (Input.GetMouseButtonUp(1))
{
timer = float.MaxValue;
}
if (Time.time <= timer)
{
Cam.active = false;
}
}
}