- Home /
Question by
edufissure · Feb 03, 2019 at 06:32 PM ·
particlesystemexplosionscriptingproblem
Explosion dont work
I have a fireball prefab, which i attatch a particle system. Then with this code i want to launch when collides ) ontriggerenter) :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Fireball script that reacts to collisions of other enemies, at the start with PlayerCharacterElyEnemy, could add others...
public class FireballMainCharacter : MonoBehaviour {
// Use this for initialization
public float speed=10.0f;
public int damage=1;
private ParticleSystem exp;
//public ParticleSystem exp;
void Start () {
// Move the object forward along its z axis speed*unit/second.
//this.gameObject.transform.Translate(0, 0, speed * Time.deltaTime);
exp = GetComponent<ParticleSystem>();
}
// Update is called once per frame
void Update () {
// Move the object forward along its z axis speed*unit/second.
//this.gameObject.transform.Translate(0, 0, speed * Time.deltaTime);
this.gameObject.transform.Translate(0, 0, speed * Time.deltaTime);
}
//Called when another object collides with this trigger
void OnTriggerEnter( Collider other){
PlayerCharacterElyEnemy player= other.GetComponent<PlayerCharacterElyEnemy>();
//Check if other object is PlayerCharacter
if( player!= null) {
Debug.Log("ElyEnmy: llamo a hurt" + player.name);
player.Hurt(damage);
//player.transform.Rotate(-75, 0, 0);
}
// Debug.Log("Other hit" + other.name);
// player.transform.Rotate(-75, 0, 0);
Explode();
//IMPORTANT: We have to destroy the fireball, once it has been collided with other object....before check with objects
Destroy(this.gameObject);
} // End OnTriggerEnd
public void Explode() {
// var exp = GetComponent<ParticleSystem>();
exp.Play();
Debug.Log("Explode done");
Destroy(gameObject, exp.duration);
}
}
But actually it doesnt work... any ideas ?? Also any tips or recommended settings to have a nice explosion ? This is for a gun shoot, i need also another to laser shoot, and cannon shoot....
Thanks
area-de-trabajo-1-091.png
(472.5 kB)
Comment