Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
  • Help Room /
This question was closed Jun 14, 2017 at 07:42 PM by codytremblay for the following reason:

Other

avatar image
0
Question by codytremblay · Jun 13, 2017 at 11:24 PM · scripting problemtags

Why ain't this working?

I'm trying to run the collision against the tags to make how much damage they take change depending on the tag. like if hit by enemy ship 25 health, bullet 1 health and ect.

here the code I pulled it off a help site but it not working.

void OnTriggerEnter2D(Collider other){ // here it checks for triggers

  if (other.gameObject.tag == "enemy")  // here I want it to check if the other object that it touching is enemy, enemy bullet, boss lazar ect;

     {health -= 25;} // here it loses health

 }


I'm using C#, Unity 5. Can anyone give me any ideas of how to get this to work. yes i gave the enemy his tag.

It says error onTriggerEnter2D, but nothing else;

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Jawchewa · Jun 13, 2017 at 11:59 PM

My guess would be that you are missing your rigidbody. To get the OnTriggerEnter2D function to trigger, at least one of your game objects needs to have a Rigidbody2D component in order for the function to be called. Although, it could still be something else causing the issue.

Comment
Add comment · Show 6 · 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 codytremblay · Jun 14, 2017 at 12:13 AM 0
Share

all $$anonymous$$e got rigidbody2d and boxcolider2d. that like the first thing i do when creating a game like this.

avatar image Jawchewa codytremblay · Jun 14, 2017 at 12:48 AM 0
Share

Actually, I think I might see the issue. The parameter for OnTriggerEnter2D has to be the type Collider2D. You have it just as a normal Collider. Change it to:

 void OnTriggerEnter2D(Collider2D other){
avatar image codytremblay Jawchewa · Jun 14, 2017 at 02:27 AM 0
Share

it worked is there a way to turn it into like an array or list ins$$anonymous$$d of using if tag = this and that.

Show more comments

Follow this Question

Answers Answers and Comments

107 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to compare audio sequences in unity 0 Answers

tagged objects problem 0 Answers

How do i add my objects to a tag 1 Answer

Multiple Tags with FindGameObjectsWithTag...? 1 Answer

Figuring out what the acceleration will be before applying force to RigidBody2D 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