Hello. I want to make it so that when this object (a projectile) collides with an enemy, it activates the particle renderer component, how would I do that? Here is my script so far. Thanks.
I also tried this and the particle renderer is not activated. How do you activate another object (I could then use the projectile as the parent for the explosion)?
function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag (“Wall”)) {
Destroy (gameObject);
};
if (other.gameObject.CompareTag (“Enemy”)) {
GetComponent(“ParticleRenderer”);
Destroy (other.gameObject);
};}
I usually have my impact effect as a game object prefab and then instantiate one on impact.
Here are parts of my bullet script that pertain to impact effects (its in c# but is easy to turn to js):
//Impact Effect declaration
public GameObject impactEffect = null; // default impact effect
// Used to create my impact effect on impact
ContactPoint contact = enterObject.contacts[0]; // the first point of contact
Quaternion rotation = gameObject.rigidbody.rotation; // can use transform.rotation if your projectile isn't a rigidbody
Instantiate(impactEffect, contact.point, rotation);
using a raycast on a bullet is more accurate, but this works fine for my grenades and such