Destroy Particles Without Shredder

Hello everyone,

I can say I am fairly new at game development and have basic programming experiment. But I am curious to learn new things. And I also appreciate this course. In this course I generally try to get things done before watching lecturer’s solution.

In the Block Breaker game, there were a smoke clone issue like projectile clone in this game. When I realise it I tried to solve and accomplished it, yeah :slight_smile: My solution for smoke was that I added a script namely “ParticleAutoDestroy” to smoke prefab. It simply checks whether the ParticleSystem alive or not in update() and Destroy if it is not.

As the same way, in laser defender; I added a ProjectileAutoDestroy to PlayerLaser prefab. In script, it finds the uppermost coordinate of the camera view as ymax in Start(). And check the position of the “particle” in Update(); if it is leaves the upper edge of the camera view, it destroy particle game object.

By doing this, it makes destroying task independent from playspace size or frame ratio (if I am not wrong about that Camera.main.ViewportToWorldPoint handle that issue itself). And also no need to add Shredder for Destroying particles (Shredder would be necessary sooner or later for the future development when number of game objects increases and game get more complex).

I just want to share :slight_smile: Have good games!


[+ 0.5f is for letting particle completely leaving the view]

2 Likes

Hello there,

As a complete beginner im very thankful for this course, is really helping to learn basics. I tend to think of this course like “does not give you fish, but teaches you how to fish” which is very helpful if you want to extend your skills.
Anyway, when i reached the shredder part i immediately thought it should have a better solution than to work with colliders since we’ve established how to get the transform of the edges of the play screen and then i found this.

Simple yet in my opinion a more pleasant option than putting a trigger.

Good job!

1 Like

i used this :

public void OnBecameInvisible() 
{
    Destroy(gameObject);
}

when they’ll get off the screen they will be destroyed

1 Like

my Solution for. Also it have 3 Points, that are great:
all Bullets ( not only the Player ) have a Lifetime.
so also the Enemys. that give me the Chance, to let Enemy Projectiles stayinside
the Playfield, for a Amont of Time, building some Sort of “Wall” the Player can
crash into.
Also they have a Firing rate, and a Patrol Script.
only the first 2 Enemy Formes, join as “Default Game” Formation, all other, following
her own Orders :smiley:

//

public float lifetime = 0.2f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    lifetime -= Time.deltaTime;
    if (lifetime <= 0)
    {
        Destroy(gameObject);
    }
}

But i have a lot of other Problems, other PPl have fixed, i try to get
fixes for, i will see :slight_smile:
have Fun.

The best way to do this is on your Fire function is with the following:

void Fire ()
{
GameObject lasershot = Instantiate(projectile, leftFire.transform.position, Quaternion.identity) as GameObject;
lasershot.GetComponent().velocity = new Vector3(0, bulletSpeed, 0);
shootSequence = !shootSequence;
Destroy(lasershot, 2);
}

The “Destroy(lasershot, 2);” allows you to destroy the GameObject that you instantiated after 2 seconds.

Hope this helped!

Privacy & Terms