void SpawnDefaultHitEffect(RaycastHit hitPosition, Transform hitTransform) { HitEffects_Master hitMaster = hitPosition.transform.root.GetComponent <HitEffects_Master>(); Quaternion quatAngle = Quaternion.LookRotation(hitPosition.normal); if (hitMaster != null) { SpawnCustomHitEffects(hitMaster, hitPosition, quatAngle); return; } if (defaultHitEffect != null) { Instantiate(defaultHitEffect, hitPosition.point, quatAngle); } }
void SpawnHitEffects(Collision hitCol, Transform hitTransform) { Quaternion quatAngle = Quaternion.LookRotation(hitCol.contacts[0].normal); HitEffects_Master hitMaster = hitTransform.root.GetComponent <HitEffects_Master>(); if (hitMaster != null) { GameObject customHitEffect = hitMaster.hitEffects; AudioClip customHitAudio = hitMaster.hitAudio; if (customHitEffect != null) { GameObject go = Instantiate(customHitEffect, hitCol.contacts[0].point, quatAngle); //To destroy particles if any. if (go.GetComponent <ParticleSystem>() != null) { go.AddComponent <ParticleSystemDestroyer>(); go.GetComponent <ParticleSystemDestroyer>().maxDuration = hitMaster.heWaitTime; } go.SetActive(true); } if (customHitAudio != null) { AudioSource.PlayClipAtPoint(customHitAudio, hitCol.contacts[0].point, hitMaster.hitVolume); } } else if (hitTransform.root.GetComponent <NPC_TakeDamage>() != null) { if (enemyHitEffect != null) { Instantiate(enemyHitEffect, hitCol.contacts[0].point, quatAngle); } } else { if (defaultHitEffect != null) { Instantiate(defaultHitEffect, hitCol.contacts[0].point, quatAngle); } } }
void SpawnCustomHitEffects(HitEffects_Master hitMaster, RaycastHit hitPosition, Quaternion quatAngle) { GameObject customHitEffect = hitMaster.hitEffects; AudioClip customHitAudio = hitMaster.hitAudio; if (customHitEffect != null) { GameObject go = Instantiate(customHitEffect, hitPosition.point, quatAngle); //To destroy particles if any. if (go.GetComponent <ParticleSystem>() != null) { go.AddComponent <ParticleSystemDestroyer>(); go.GetComponent <ParticleSystemDestroyer>().maxDuration = hitMaster.heWaitTime; } go.SetActive(true); } if (customHitAudio != null) { AudioSource.PlayClipAtPoint(customHitAudio, hitPosition.point, hitMaster.hitVolume); } }