public void FireProjectile(bool isFiringRight) { if (Time.time > shootRateTimeStamp && (!unit.IsDead()) && isLoaded) { //projectile instatiation Vector3 projPosition = new Vector3(transform.position.x + (isFiringRight ? posOffsetX : -posOffsetX), transform.position.y + posOffsetY, transform.position.z); GameObject projectileInstance = Instantiate(projectilePrefab, projPosition, Quaternion.identity, GameObject.Find("Projectiles").transform); projectileInstance.name = projectilePrefab.name; projectileInstance.GetComponent <ProjectileScript>().SetParent(gameObject); ProjectileScript projectileMovement = projectileInstance.GetComponent <ProjectileScript>(); projectileMovement.FaceAndExpire(isFiringRight); shootRateTimeStamp = Time.time + shootRate; //cast animation if (castAnim) { GameObject casts = Instantiate(castAnim, projPosition, Quaternion.identity); casts.name = castAnim.name; casts.GetComponentInChildren <CastMovement>().DefineParent(gameObject); SpriteRenderer castsR = casts.GetComponentInChildren <SpriteRenderer>(); castsR.flipX = !isFiringRight ? castsR.flipX = true : false; Destroy(casts, castAnimLength); if (weaponscript) { if (weaponscript.GetNeedsReload()) { isLoaded = false; } } } } }