using UnityEngine;
using System.Collections;
public class shooter2 : MonoBehaviour
{
public GameObject[] projectiles;
int projectilesNo;
public float speedFactor;
public float delay;
public float delayTimer = 2f;
float timer;
// Use this for initialization
void Start()
{
timer = delayTimer;
}
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (Input.GetMouseButtonDown(0) && timer <= 0)
{
GameObject clone = (GameObject)Instantiate(projectiles[projectilesNo], transform.position, Quaternion.identity);
clone.GetComponent<Rigidbody2D>().velocity = -transform.right * speedFactor;
projectilesNo = Random.Range(0, 2);
timer = delayTimer;
}
}
IEnumerator Shoots()
{
while (true)
{
yield return new WaitForSeconds(delay);
}
}
}
heres the script, im trying to instantiate two different projectiles while moving them while spawning them with random. range. it works it just spawning both of the projectiles at once can anyone tell me why its doing this. im trying to get them to instantiate individually thanks