IEnumerator Attack() { currentlyShooting = true; // Attack animation and sound //animator.SetTrigger("attack"); AudioSource.PlayClipAtPoint(attackSoundEffect, new Vector3(0, 0, 0)); if (weaponPrefab.GetCastTime() > 0) { yield return(new WaitForSeconds(weaponPrefab.GetCastTime())); } int weaponDirection = spriteRenderer.flipX ? -1 : 1; if (isBackwards) { weaponDirection *= -1; } Vector3 weaponWorldPosition = weaponSpawnPoint.position; Vector3 weaponLocalPosition = transform.InverseTransformPoint(weaponWorldPosition);//new Vector3(transform.position.x + weaponDirection * 0.5f, transform.position.y + 0.5f, transform.position.z); if (spriteRenderer.flipX) { weaponLocalPosition.x *= -1; } if (isBackwards) { weaponLocalPosition.x *= -1; } weaponWorldPosition = transform.TransformPoint(weaponLocalPosition); Castable weapon = Instantiate(weaponPrefab, weaponWorldPosition, Quaternion.identity); //weapon.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer"); if (weaponPrefab is Bullet) { Bullet bullet = (Bullet)weapon; bullet.direction = weaponDirection; } yield return(new WaitForSeconds(1f)); currentlyShooting = false; }
IEnumerator Cast() { // Attack animation and sound animator.SetTrigger("attack"); AudioSource.PlayClipAtPoint(attackSoundEffect, new Vector3(0, 0, 0)); if (weaponPrefab.GetCastTime() > 0) { yield return(new WaitForSeconds(weaponPrefab.GetCastTime())); } int weaponDirection = spriteRenderer.flipX ? -1 : 1; Vector3 weaponWorldPosition = weaponSpawnPoint.position; Vector3 weaponLocalPosition = transform.InverseTransformPoint(weaponWorldPosition);//new Vector3(transform.position.x + weaponDirection * 0.5f, transform.position.y + 0.5f, transform.position.z); if (spriteRenderer.flipX) { weaponLocalPosition.x *= -1; } weaponWorldPosition = transform.TransformPoint(weaponLocalPosition); Castable weapon = Instantiate(weaponPrefab, weaponWorldPosition, Quaternion.identity); //weapon.gameObject.layer = LayerMask.NameToLayer("IgnorePlayer"); if (weapon.GetCastType() == Castable.CastType.Sustained) { currentSustainedCast = weapon; animator.SetBool("shield", true); } if (weaponPrefab is Bullet) { Bullet bullet = (Bullet)weapon; bullet.direction = weaponDirection; } weapon.StartCast(this); }