#Instantiating and Destroying
1 messages · Page 1 of 1 (latest)
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PlayerMovement>())
{
//This next line of code will console log an error until Challenge 3 is complete.
gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
Destroy(other.gameObject);
//Challenge 4:
var effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
Destroy(effect, 1f);
}
}
I was figuring this is what you mean, but it still is not working...I am storing the instantiate into effect which is local to the function, then trying to destroy it 1 second later.
as long as the current object isnt destroyed before that happens, it should be fine
maybe add a debug to see if it ever happens
If it gets stored into effect?
well yea if the code even runs, i dont really know whats not working specifically
Going to be a couple of messages to show before, during and debug
Before Run:
During Run:
Debug:
FX_Fireworks_Blue_Small (Clone) (UnityEngine.ParticleSystem)
UnityEngine.Debug:Log (object)
FinishPad:OnTriggerEnter (UnityEngine.Collider) (at Assets/Scripts/FinishPad.cs:34)
and its never being destroyed?
so it still never deletes the clone ever nah
is the script or object that spawns the particles being destroyed?
this is assigned on FinishPad which is never destroyed...the player is, but not the finishpad
can you do this and see if its ever destroyed then? i really would just assume the script is being destroyed
IEnumerator DestroyParticles(INSERTTYPE obj, float delay)
{
yield return new WaitForSeconds(delay);
Debug.Log("Destroying");
Destroy(obj);
}
unless you are instantiating the object twice, once somewhere else
Where do you want that? Just at the bottom?
call the coroutine rather than Destroy()
because at least you can see the debug happen when its supposed to destroy. If you see "Destroying" then that means u are just instantiating 2 of the objects
it doesnt like the inserttypew
sorry...I am really new and trying to figure it out as well
yes, insert the type there
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PlayerMovement>())
{
var effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
StartCoroutine(effect, 2);
//This next line of code will console log an error until Challenge 3 is complete.
gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
Destroy(other.gameObject);
//Challenge 4:
}
}
IEnumerator DestroyParticles(INSERTTYPE obj, float delay)
{
yield return new WaitForSeconds(delay);
Debug.Log("Destroying");
Destroy(obj);
}
I figure I have to pass the two arguments of the obj name and the amount of time I want
i didnt know what the data type of the object is so i just wrote INSERTTTYPE to tell you to insert it
StartCoroutine(DestroyParticles(effect, 2));
then change INSERTTYPE to the type the object is. i believe its a game object right?
huh can you show what you put there
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PlayerMovement>())
{
ParticleSystem effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
StartCoroutine(effect, 2);
//This next line of code will console log an error until Challenge 3 is complete.
gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
Destroy(other.gameObject);
//Challenge 4:
}
}
IEnumerator DestroyParticles(ParticleSystem obj, float delay)
{
yield return new WaitForSeconds(delay);
Debug.Log("Destroying");
Destroy(obj);
}
}
you forgot the first part
duh
I didnt call the actual method...is that the right term?
Destroying
UnityEngine.Debug:Log (object)
FinishPad/<DestroyParticles>d__6:MoveNext () (at Assets/Scripts/FinishPad.cs:39)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
but never destroyed
basically yea
then you are spawning 2 i assume
just curious, does the particle system not stop?
or is the issue just that the gameobject is in the scene
you can destroy the obj.gameObject if you want to destroy the entire object
that is probably what it is
its a short clip...like 3 seconds so it does stop playing
but I figure its good form to remove items not needed
so that worked
which means I can probably call effect.gameObject without the coroutine
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PlayerMovement>())
{
//This next line of code will console log an error until Challenge 3 is complete.
gameHandler.RemovePlayerCubeFromList(other.gameObject.GetComponent<PlayerMovement>());
Destroy(other.gameObject);
//Challenge 4:
ParticleSystem effect = Instantiate(playerDeadEffect, finishPadPos, Quaternion.identity);
Destroy(effect.gameObject, 2f);
}
}
Final code that worked
so before it was destroying it, however it was only destroying the component ParticleSystem