Because I don’t do c# much but anyways I’m trying to do this thing where it will destroy after 2 seconds when it adds time.
using UnityEngine;
using System.Collections;
public class BossAnimation : MonoBehaviour {
// Use this for initialization
public bool animate = false;
public GameObject boss;
public Camera cam;
public GameObject bubbles;
public double NumberOfSecondsToWait;
private bool IsTiming = false;
private double timer;
void Update ()
{
if(animate)
{
iTween.MoveTo(gameObject, iTween.Hash("path", iTweenPath.GetPath("Boss Path"), "orienttopath", true, "time", 120));
animate = false;
}
if(transform.position.z < -40)
{
boss.transform.position = new Vector3(-95,-18,-40);
Destroy(bubbles.gameObject);
cam.camera.enabled = true;
beginTimer ();
}
if(IsTiming)
{
timer += Time.deltaTime;
}
if (timer > NumberOfSecondsToWait) //This wont call...
{
cam.camera.enabled = false;
Destroy (gameObject);
print ("Time has passed!");
}
}
void beginTimer()
{
timer = 0;
IsTiming = true;
}
}
It all works until I check for the time. I’m sure the answer is pretty simple but I’m not good with c# logic but I have to make this work in c# so my iTween path works. Help would be great!
i just wanted to make sure, does while loop help in such cases and by help i mean is it more efficient or something like that? while (isTiming) { timer += Time.deltaTime; if (timer >= 2.0f) { isTiming = false; //do whatever thats needed here break; } } wud this piece of code make sense?
– sajithsathes