// Update is called once per frame void Update() { float probability = Time.deltaTime * shotsPerSecond; if (Random.value < probability && GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("Idle") && canFire && ammoManager.HasAmmo()) { //Instantiate GameObject firedProjectile = Instantiate(projectile, new Vector3(transform.GetChild(0).position.x, transform.GetChild(0).position.y, -0.5f), Quaternion.identity); firedProjectile.GetComponent <Projectile>().EnemyParent = gameObject; //Set Color firedProjectile.GetComponent <SpriteRenderer>().color = GetComponent <SpriteRenderer>().color; firedProjectile.GetComponent <Light>().color = GetComponent <SpriteRenderer>().color; //Set trail Color firedProjectile.GetComponent <TrailRenderer>().startColor = GetComponent <SpriteRenderer>().color; firedProjectile.GetComponent <TrailRenderer>().endColor = GetComponent <SpriteRenderer>().color; // Set Projectile velocity float speed = firedProjectile.GetComponent <Projectile>().ProjectileSpeed; firedProjectile.GetComponent <Projectile>().ProjectileVelocity = player.transform.position - transform.GetChild(0).position; canFire = false; ammoManager.DecreaseAmmo(); } //if (Input.GetKeyDown(KeyCode.Space)) //{ // DestroyEnemy(); //} }