Question by
gamer777 · Dec 07, 2017 at 01:22 AM ·
invokerepeating
Invoke repeating wont repeat
Hi invoke repeating doesnt repeat it just invoke once but doesnt repeate every second. A little help would be appreciated. Thanks! Transform Player; float RotSpeed = 90f; Vector2 dire;//direction of the bullet bool isReady;//when bullet set public GameObject bullet1; // Update is called once per frame void Start() { InvokeRepeating("FireBullet", 1f,1f); }
void Update()
{
}
void FireBullet () {
if(Player==null)
{
GameObject player = GameObject.Find("Player");
if(player!= null)
{
Player = player.transform;
GameObject bullet = (GameObject)Instantiate(bullet1);
bullet.transform.position = transform.position;
Vector2 direction = player.transform.position - bullet.transform.position;
bullet.GetComponent<EnemyBulletMove>().SetDirection(direction);
}
}
Comment
Answer by Hellium · Dec 07, 2017 at 08:21 AM
I think the InvokeRepeating works correctly. Simply put a Debug.Log at the beginning of your function to make sure.
The problem comes from your function. Try this :
void FireBullet ()
{
if(Player==null)
{
GameObject player = GameObject.Find("Player");
if(player!= null)
{
Player = player.transform;
}
}
if( Player != null )
{
GameObject bullet = (GameObject)Instantiate(bullet1);
bullet.transform.position = transform.position;
Vector2 direction = Player.transform.position - bullet.transform.position;
bullet.GetComponent<EnemyBulletMove>().SetDirection(direction);
}
}
Your answer