public void SetCastersProjectileAbilty(ProjectileAbility projectileAbility) { castersProjectileAbility = projectileAbility; ScriptableProjectileAbility scriptableProjectile = (ScriptableProjectileAbility)projectileAbility.Ability; damage = scriptableProjectile.Damage; initialForce = scriptableProjectile.InitialForce; gravityAffected = scriptableProjectile.GravityAffected; projectileRigidbody.useGravity = gravityAffected; RangeCutoff = scriptableProjectile.Range; }
void Impact(GameObject hitGameObject, Vector3 hitPoint, Vector3 hitNormal) { if (castersProjectileAbility != null) { //First check if it has a health component Debug.Log("Projectile Hit"); ScriptableProjectileAbility projectileAbility = castersProjectileAbility.Ability as ScriptableProjectileAbility; if (projectileAbility == null) { Debug.LogError("Projectile: ScriptableAbility is not of type ScriptableProjectileAbility"); } castersProjectileAbility.Hit(hitGameObject, projectileAbility != null ? projectileAbility.Damage : 0.0f, hitPoint, transform.forward, hitNormal); } else { CharacterBase hitCharacter = AttackAbility.GetParentCharacterBase(hitGameObject.transform); if (hitCharacter) { hitCharacter.TakeDamage(damage); } if (ImpactSound && ImpactAudioSource) { ImpactAudioSource.PlayOneShot(ImpactSound); } } if (ImpactSound) { transform.GetComponent <MeshRenderer>().enabled = false; transform.GetComponent <SphereCollider>().enabled = false; this.enabled = false; for (int i = 0; i < transform.childCount - 1; i++) { transform.GetChild(i).gameObject.SetActive(false); } Destroy(gameObject, ImpactSound.length); } else { Destroy(gameObject); } }
private void ShootProjectile() { ScriptableProjectileAbility projectileAbility = (ScriptableProjectileAbility)Ability; if (projectileAbility.ProjectileGameObject == null) { return; } GameObject projectileObject = useableAbility.InstantiateObject(projectileAbility.ProjectileGameObject.gameObject, useableAbility.Origin.position, useableAbility.Origin.rotation); Projectile projectile = projectileObject.GetComponent <Projectile>(); //Set the projectiles caster ability to this if (projectile != null) { projectile.SetCastersProjectileAbilty(this); } }