/// <summary> /// Fire projectile then temporarily set an animation override. /// </summary> virtual protected IEnumerator ShootRoutine() { // Instantiate prefab GameObject go = (GameObject)GameObject.Instantiate(projectilePrefab); Projectile projectile = go.GetComponent <Projectile>(); if (projectileAimer != null) { go.transform.position = enemy.transform.position + (Vector3)projectileAimer.GetAimOffset(enemy); } else { go.transform.position = enemy.transform.position; } if (projectile != null) { // Fire projectile if the projectile is of type projectile Vector2 direction = new Vector2(enemy.LastFacedDirection != 0 ? enemy.LastFacedDirection : 1, 0); // Use aimer to get direction fo fire if the aimer is configured if (projectileAimer != null) { direction = projectileAimer.GetAimDirection(enemy); } projectile.Fire(damageAmount, damageType, direction, enemy); } enemy.AddAnimationOverride(overrideName); isShooting = true; yield return(new WaitForSeconds(shootTime)); enemy.RemoveAnimationOverride(overrideName); isShooting = false; }
/// <summary> /// Instatiates a projectile. /// </summary> /// <param name="attackIndex">Index of the projectile to instantiate.</param> virtual public void InstantiateProjectile(int attackIndex) { // If attack index == -1 then we should use the deferred attack. if (attackIndex == -1) { attackIndex = deferredAttackIndex; } // Instantiate prefab GameObject go = (GameObject)GameObject.Instantiate(attacks[attackIndex].projectilePrefab); Projectile projectile = go.GetComponent <Projectile>(); if (projectileAimer != null) { go.transform.position = character.transform.position + (Vector3)projectileAimer.GetAimOffset(character); } else { go.transform.position = character.transform.position; } if (projectile != null) { // Fire projectile if the projectile is of type projectile Vector2 direction = new Vector2(character.LastFacedDirection != 0 ? character.LastFacedDirection : 1, 0); // Use aimer to get direction fo fire if the aimer is configured if (projectileAimer != null) { direction = projectileAimer.GetAimDirection(character); } projectile.Fire(attacks[attackIndex].damageAmount, attacks[attackIndex].damageType, direction, character); } // If the projectile is found and the go is still alive call finish if (projectile != null && go != null) { projectile.Finish(); } }
/// <summary> /// Fires the grapple. /// </summary> virtual protected void FireGrapple() { if (ropeGo == null) { ropeGo = (GameObject)GameObject.Instantiate(ropePrefab); ropeGo.SetActive(false); } // Instantiate grapple first time if (grapple == null) { GameObject go = (GameObject)GameObject.Instantiate(grapplePrefab); grapple = go.GetComponent <GrapplingHookProjectile> (); } // Fire grapple grapple.transform.position = character.Transform.position + (Vector3)(aimer == null ? Vector2.zero : aimer.GetAimOffset(character)); grapple.Fire(0, DamageType.NONE, aimer == null ? new Vector2(0, 1) : aimer.GetAimDirection(character), character); maxRopeDistance = 0; }