And before you tell me to use google or to search in the web, let me tell you I’ve been researching about this for about 3 hours and I simply can’t find an answer. All I find is old topics that work with the old particle system and we all know most of that code is obsolete now.
I’m kinda new with Unity so if you could be quite specific, even better. My problem is this:
I have 3 main scripts for this, one for the enemy health, one for the player weapon and one for the action of firing itself. In enemy health I specify enemy’s status and I use OnCollisionEnter to deal damage when my bullet hits, with a reference to my player weapon script for damage and other data. The firing scripts basically instanciates the bullet with a rigidbody component and adds the movement.
Now I can’t find a way to simply play an animation in the spot where the bullet hits when it collisions with the enemy. That’s all I want and I can’t get to understand how to work with ParticleSystem, GetComponent and “Play()” to make it work as I read here and there.
This is my code to instanciate the bullet itself:
void Shoot()
{
shot = Instantiate(shotEmitter) as GameObject;
shot.transform.position = transform.position + Camera.main.transform.forward * 2;
Rigidbody rb = shot.GetComponent<Rigidbody>();
rb.velocity = Camera.main.transform.forward * 40;
Destroy(shot, 2f);
}
And to cause the damage and destroy the bullet on contact:
void OnCollisionEnter(Collision _col)
{
if (_col.collider.gameObject.tag == "Bullet")
{
GameObject theDamage = GameObject.Find("Gun");
PlayerWeapon damageFromWeapon = theDamage.GetComponent<PlayerWeapon>();
currentEnemyHealth -= damageFromWeapon.weaponDamage;
WeaponFiring theShot = theDamage.GetComponent<WeaponFiring>();
Destroy(theShot.shot);
}
}
Is there any way to add a particle system (I acutally created one in an empty object and all) to the point where it hits? If you need any other info let me know.