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
0
Question by SteveGreenFire · Dec 28, 2014 at 02:46 PM · c#not workingflipontriggerexit

Unity2D onTriggerExit2D not working!! Help!!

Hey guys,

So basically I am creating a 2D platformer with Unity and I have run into a problem.

I am trying to create a boundary box around my map, so that when enemies inside hit the edges of the map, they switch direction.

I am quite sure that the code i have written is good but can someone please check it out for me? It is driving me crazy as it should be working!!

 using UnityEngine;
 using System.Collections;
 
 public class Boundaries : MonoBehaviour 
 {    
     private GameObject Enemies;
 
     // Use this for initialization
     void Start () 
     {
         Enemies = GameObject.FindGameObjectWithTag("Enemy");
     }
     
     // Update is called once per frame
     void Update () 
     {
 
     }
 
     void onTriggerExit2D(Collider2D other)
     {
         Debug.Log ("Left The Building");
 
         if (other.gameObject.tag == "Enemy")
         {
             Debug.Log ("Left The Building");
             other.gameObject.transform.rotation = Quaternion.Euler (transform.rotation.x, 180, transform.rotation.z);
             //Enemies.gameObject.transform.rotation = Quaternion.Euler (transform.rotation.x, 180, transform.rotation.z);
         }
 
     }
 }

Just to let you know the boxCollider2D around the map has been set to trigger, and the enemies have two box collider2D's, one is a trigger and one isn't.

Not even the debug.log's are working !! :S

Thanks :)

Comment
Add comment · Show 2
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 jenci1990 · Dec 28, 2014 at 04:18 PM 0
Share

Use OnTriggerExit2D not onTriggerExit2D

avatar image SteveGreenFire · Dec 30, 2014 at 01:42 PM 0
Share

Hey guys, managed to solve it ... thanks for all your answers :)

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by m_pangolin · Dec 28, 2014 at 04:52 PM

Instead of writing onTriggerExit2D you should write OnTriggerExit2D (Capital O)

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
avatar image SteveGreenFire · Dec 28, 2014 at 06:46 PM 0
Share

Oh my god, just for a capitalization issue! thanks so much :D haha great now the debug.log's are working ... but i still cant get the sprite to flip round and go the other direction.... any ideas?

avatar image
0

Answer by kwmx · Dec 28, 2014 at 08:48 PM

Try using

 transform.localRotation
Comment
Add comment · 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
0

Answer by ShootingStar · Dec 28, 2014 at 10:27 PM

Here's one way to get the sprite to flip and go to the other direction. This first flips the gameobject, then inverts its velocity to the opposite direction:

 other.gameObject.transform.Rotate(0, 180, 0, Space.Self);
 other.gameObject.rigidbody2D.velocity = -other.gameObject.rigidbody2D.velocity;
Comment
Add comment · 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

7 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Flip over an object (smooth transition) 3 Answers

How to do a sprite flip 1 Answer

Problem with OnTriggerExit(). If loop not passing to next loop. 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