If I have a class, and In another script, I create an instance of that class, is the update function usable?
Nothing I put in it seems to run.
The class:
using UnityEngine;
using System.Collections;
public class MM_Timer {
float delayy;
float time;
public bool tik = false;
bool randmode;
float min;
float max;
bool paused = false;
void Update () {
if (time < delayy && tik == false && paused == false)
{
time += Time.deltaTime;
}
else if (!paused)
{
tik = true;
if(randmode){
delayy = Random.Range(min, max);
}
}
}
public bool tick(){
if (tik){
tik = false;
return true;
}
else{return false;}
}
public void start(){paused = false;}
public void puase(){paused = true;}
public MM_Timer(float delay, bool autostart){
delayy = delay;
if (!autostart) paused = true;
}
public MM_Timer(float minDelay, float maxDelay, bool autostart){
min = minDelay;
max = maxDelay;
if (!autostart) paused = true;
}
}
Just in case, my Script:
using UnityEngine;
using System.Collections;
public class bow : MonoBehaviour {
public GameObject arrow;
public Transform shotpos;
bool canfire = true;
public static float firerate = 0.5f;
MM_Timer timer = new MM_Timer (firerate, true);
void Update () {
if(Input.GetButton("Fire1")){
if(canfire){
Instantiate(arrow, shotpos.position, transform.rotation);
canfire = false;
}
}
if(timer.tick()){
canfire = true;
}
}
}