• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Thomaidis · Jun 06, 2016 at 02:20 PM · unity 5unity 2dparticle system2d platformerdeath

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. alt text

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.

untitled.png (22.0 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hellium · Jun 06, 2016 at 02:30 PM 0
Share

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)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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).

Comment
Add comment · Show 9 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Thomaidis · Jun 06, 2016 at 02:52 PM 0
Share

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!

avatar image Thomaidis · Jun 06, 2016 at 03:08 PM 0
Share

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); }

avatar image tanoshimi Thomaidis · Jun 06, 2016 at 04:13 PM 0
Share

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?

avatar image Thomaidis tanoshimi · Jun 06, 2016 at 05:13 PM 0
Share

@tanoshimi

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

Show more comments
avatar image imaxus Thomaidis · Jun 06, 2016 at 06:04 PM 1
Share

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).

avatar image Thomaidis imaxus · Jun 06, 2016 at 06:14 PM 0
Share

will do that!

thanks again :)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Jumps When Falling (Unity2D) 0 Answers

Problem in displaying the right text on screen 1 Answer

Implement Zoom(using UI Canvas) in Unity 2d game. 0 Answers

How to rotate transform only on its Y axis? 1 Answer

Bone character 2d stretch or separate 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges