Hello. I have a question that i cant solve my self. I am making tower defence game and i added rapid fire upgrade that change time value in the time but its still the same speed because it does not check it when i buy that upgrade. How can i make that when i purchase it, it will check the timer after the upgrade is applied then it will start using the new time i hope you understand. I am using unity 5 beta pro. Here is the timer script:
using UnityEngine;
using System.Collections;
public class TurretShooting : MonoBehaviour {
public Rigidbody cannonball;
public Transform cannonend;
private float cannonballspeed = 1500f;
public float firerate = 3.0f;
public void Start () {
InvokeRepeating("shootcannonball", 1, firerate);
}
void shootcannonball () {
Rigidbody cannonballrig;
cannonballrig = Instantiate (cannonball, cannonend.position, cannonend.rotation) as Rigidbody;
cannonballrig.AddForce (-cannonend.forward * cannonballspeed);
}
}
See that firerate in invokerepeating timer? yeah the upgrade change that value but it does not detect it and keeps using the old time. How can i make that it would check in this upgrade script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CannonRateOfFireUpgr : MonoBehaviour {
private Databasestorage database;
private int Cost = 15;
public GameObject Cannon1;
public GameObject Cannon2;
// Use this for initialization
public void increaserateoffire () {
database = GameObject.Find ("Main Camera").GetComponent<Databasestorage> ();
//Cannon3 = GameObject.Find ("Cylinder001").GetComponent<TurretShooting> ();
//Cannon4 = GameObject.Find ("Cylinder001").GetComponent<TurretShooting> ();
if (Cannon1.GetComponent<TurretShooting> ().firerate < 0.2f && Cannon2.GetComponent<TurretShooting> ().firerate < 0.2f) {
transform.Find ("CannonRateOfFireText").GetComponent<Text> ().text = "Cannon Rate Of Fire
MAX UPGRADED";
} else {
if (database.money > Cost) {
database.money -= Cost;
Cannon1.GetComponent<TurretShooting> ().firerate -= 0.1f;
Cannon2.GetComponent<TurretShooting> ().firerate -= 0.1f;
//Cannon3.GetComponent<TurretShooting>().firerate -= 0.1f;
//Cannon4.GetComponent<TurretShooting>().firerate -= 0.1f;
Cost += 12;
transform.Find ("CannonRateOfFireText").GetComponent<Text> ().text = "Cannon Rate Of Fire
Cost " + Cost;
}
}
}
}
I tried adding the Start() in the button but it start a new timer and then its shooting 2 bullets at 1 time… that is bad. Soo how can i check it? sorry again if this is very confusing.