- Home /
Particle System for Death effect
Hello,
I'm very new to programming and I was trying out a tutorial on a 2D platformer by AndroidAuthority.com.
The reason I'm here is because even though I have followed the tutorial, probably, perfectly I still can't get the result I want.
I'm using a Particle System for the death of my character when triggered by an obstacle (hazard). The code that the tutorial said to add is the bold text: void OnTriggerEnter2D(Collider2D other) {
**Instantiate(Explode, player.transform.position, player.transform.rotation);**
if (other.tag == "Player")
{
player.transform.position = start.position;
}
}
and then I made an Empty Game Object in Unity, named it Explode and as the tutorial says, tried to add it to the hazard only to find out that because of the compiler error that doesn't recognize "Explode" I can't do anything to the Hazards.
also here's the tutorial: http://www.androidauthority.com/create-a-2d-platformer-for-android-in-unity-part-2-694434/
Thanks in advance ! Sorry for my bad explanation, as i said I'm new at this.
Please, provide the full script.
The class name may not match the file name, or you have an error in a script (not necessarily the Hazard script)
Answer by imaxus · Jun 06, 2016 at 02:34 PM
Hi,
First look at this (you need to learn how to use unity documentation :)) :
https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
To solve your problem add :
[SerializedField]
GameObject Explode;
on the beggining of your class, then in Editor drag and drop the object with particles to your script field named Explode (script attached to your game object).
Thank you for the quick reply.
Did it and it works! The tutorial doesn't say anything about that little piece of code needed and as a beginner I couldn't have guessed it.
I'm gonna check the unity documentation, looks helpful. Thanks for that link as well!
Since you've been so helpful allow me to ask just one more thing.
$$anonymous$$y character now jumps infinitely, meaning I can tap jump as many times as I want and basically fly.
In the tutorial it shows how to "ground the character and even though I once again did everything as said it just ignores it and still jumps infenitely.
I did layer the ground sprite as "Ground" and also selected layer: Ground in character's options "WhatIsGround: " and also made a CheckGround Empty Game Object in Hierarchy that is under character.. my code is this :
public Transform groundCheck;
public Layer$$anonymous$$ask whatIsGround;
public float groundCheckRadius;
and
void FixedUpdate() { onGround = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround); }
And what values have you given to groundCheckRadius and whatIsGround? Where is your groundCheck transform placed in the scene? Where do you actually check the value of onGround?
radius is set to 0.1 as instructed in the tutorial, and the CheckGround Game Object is at the bottom of the character as instructed as well.
I have the set the -> WhatIsGround: Ground for the character using the layer I created and set for the ground sprite.
The tutorial doesn't have any other instructions on that, so my best guess is there's either something missing from the tutorial or I'm missing something
So u need to allow player to jump only when it is grounded. This is if statement u should use:
if( Input.GetButton("Jump") && onGround){
//do jump
}
To set jump button : edit->project settings->input ->inspector -> andthere u have buttons and thier mapping. Or u can use Input.$$anonymous$$eyCode (or sth like this, i dont use it much).
Your answer
Follow this Question
Related Questions
Character Jumps When Falling (Unity2D) 0 Answers
How to check if a enemy is moving up or down? 1 Answer
Error trying to parse multiple IF statements of a KeyInput and Collider 1 Answer
Creating a splitting effect in Unity 1 Answer
Help with bombs destroying colliders in different position from gameobject 0 Answers