Question by
Luka-Tubic · May 16, 2016 at 01:37 PM ·
pausedelay
Pause between action
using UnityEngine; using System.Collections;
public class enemyshoot : MonoBehaviour {
public Transform spawnbulletenemy;
public Rigidbody bullet;
public float brzinametka = 5f;
public Transform igrac;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Rigidbody metakkojileti;
metakkojileti = Instantiate (bullet, spawnbulletenemy.position, spawnbulletenemy.rotation) as Rigidbody;
metakkojileti.AddForce (spawnbulletenemy.forward * brzinametka);
}
void shoot()
{
}
}
This is my code , I want delay before evry shoot , is there any way to avoid corutines they look very complicated ?
Comment
Answer by vittu1994 · May 16, 2016 at 02:37 PM
Easiest is to do a couroutine. By looking at the script its just firing all the time and i guess its what you want? You can do this easy by doing a couroutine and looping its content.
void Start()
{
StartCouroutine(Shoot());
}
IEnumerator Shoot()
{
while(canShoot == true)
{
//your code
yield return new WaitForSeconds(1);
}
}
There are other ways to control your loop if you dont want it to shoot at all times
Your answer
![](https://koobas.hobune.stream/wayback/20220612080917im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make pause beetwen action 0 Answers
C# Simple delay at void Update? 2 Answers
Help with corutines 1 Answer
Make my moving platforms pause at its endpoints using c# 2 Answers