- Home /
Fire rate problem [C#]
Hello everybody ! Today i'm creating a space shooter but i have a problem, i use "invokereapeating" to make my Boss fire every 2 seconds but it fire every ticks ! Some one can help me ? This is my code :
using UnityEngine; using System.Collections;
public class BossManager : MonoBehaviour { public float maxBossLife = 100f;
public float BossLife;
public float FireRate = 50f;
public GameObject Explosion;
public GameObject BossBullet;
void Start () {
BossLife = maxBossLife;
}
void Update () {
InvokeRepeating("BossAttack", 0f, 2f);
if(BossLife <= 0f)
{
PlayExplosion();
GameManager.Score += 300;
Destroy(gameObject);
}
}
public void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "PlayerBullet")
{
BossLife = BossLife - PlayerBullet.PlayerBulletDamage;
}
}
public void BossAttack()
{
GameObject playerShip = GameObject.Find("Player");
if (playerShip != null)
{
GameObject Bullet = (GameObject)Instantiate(BossBullet);
Bullet.transform.position = transform.position;
Vector2 direction = playerShip.transform.position - Bullet.transform.position;
Bullet.GetComponent<EnnemyBullet>().SetDirection(direction);
}
}
void PlayExplosion()
{
GameObject explosion = (GameObject)Instantiate(Explosion);
explosion.transform.position = transform.position;
}
}
Thank you that read my post, i hope you have an answer ! Bye, xyHeat !
Sorry i forget i have change this ! (i put the good one)
Answer by saschandroid · Feb 11, 2016 at 02:27 PM
Move InvokeRepeating("BossAttack", 0f, 2f);
into Start()
Your answer
Follow this Question
Related Questions
Change Gun Fire Rate 3 Answers
Rapid fire to Instantiated prefab 2 Answers
Prevent bullets from trailing behind crosshair at high range? 1 Answer
How to add a gunshot sound to this script? 1 Answer
My tower defense script fires too often 5 Answers