Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by E3S21I · Jan 17, 2015 at 06:49 PM · script error

OnTriggerExit with 2D Colliders?

I want to to make a 2D space game (average) and when I shoot, my sprite keeps going continuously up. I have set a cube surrounding the outside of the game while the "Is Trigger" is selected with this script:

using UnityEngine; using System.Collections;

public class DestroyCollider : MonoBehaviour { void OnTriggerExit(Collider other) { Destroy(other.gameObject); } }

Shots are still escaping and is spamming my hierarchy!? (Sorry im new tho Unity answers)

Comment
Add comment · Show 6
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 Graham-Dunnett ♦♦ · Jan 17, 2015 at 06:49 PM 1
Share

I was very close the rejecting your question because your code is not formatted.

avatar image Ultroman · Jan 18, 2015 at 04:16 PM 0
Share

Those are the weirdest tags ever. That is not good use of them.

avatar image E3S21I · Jan 18, 2015 at 04:25 PM 0
Share

Thank you, i got it sorted today! Sorry about that.

avatar image E3S21I · Jan 18, 2015 at 04:26 PM 0
Share

I have done that before OnTriggerExit2D and it wouldnt work, but i realised that I had 'Is Trigger' ticked and changed OnTriggerExit2D to OnCollisionExit/Enter2D and really did what I wanted!

Thank you so much for replying too me and giving amazing imformation to proceed onto my game project!

avatar image richyrich · Jan 18, 2015 at 05:01 PM 1
Share

@E3S21I Ticking answers helps other users find solutions that work

27269-howtotickananswer.png (2.0 kB)
Show more comments

1 Reply

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

Answer by Chris333 · Jan 18, 2015 at 04:13 PM

Hi,

instead of using

 void OnTriggerExit(Collider other)

use the 2D version, because you are using a sprite.

 void OnTriggerExit2D(Collider2D other)

http://docs.unity3d.com/500/Documentation/ScriptReference/Collider2D.OnTriggerExit2D.html

You could also change the 3D cube for the level boundary to a empty gameobject and give this object a BoxCollider2D, because you are using 2D sprites.

A good idea is also to take a look into the following project(if you dont know it already) because it is a example of a 2D space shooter with 3D Objects. http://unity3d.com/learn/tutorials/projects/space-shooter

Comment
Add comment · Show 1 · 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

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.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Fps controller script error 0 Answers

Script error 1 Answer

Something is wrong with unity 0 Answers

PlayerController C# Script error? Help! 1 Answer

Changing Force of object 1 Answer


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