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 Apr 02, 2017 at 01:54 PM by Asmode for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Asmode · Apr 02, 2017 at 10:01 AM · ontriggerenter

OnTriggerEnter work only once

Hello everyone, I'm using unity since a week and i get a problem with my trigger.

Resume : I make a runner where the main corridor is divided in 3 section. I have an IA that will spawn in front of the player sometime. The IA will run in front of the player and have to dodge obstacles.

To do the dodging system i have created 3 capsules in from of my IA and check il the capsule collide with an obstacle.

The result is pretty great so far, but my fonction "OnTriggerEnter" is workiing only once and i dont know why.

Exemple ; The first obstacle is on the A and B line, The function return A , B (when the trigger enter on collision with an obstacle) and, "A passe faux", "B passe faux". (when the trigger exit the obstacle.

But is then il there is another obstacle on the A and B section, the trigger will not detect the collision.

Could you help me please ? :) Here is my code Ps : The code is component of each capsule

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class detect_col_poulet : MonoBehaviour { public bool capsuleA = false; public bool capsuleB = false; public bool capsuleC = false;

 void OnTriggerEnter(Collider col)
 {
     if (gameObject.name == "capsuleA") 
     {
         capsuleA = true;
         Debug.Log ("A");
     }
     if (gameObject.name == "capsuleB") 
     {
         capsuleB = true;
         Debug.Log ("B");
     }
     if (gameObject.name == "capsuleC") 
     {
         capsuleC = true;
         Debug.Log ("C");
     }
 }

 void OnTriggerExit(Collider col)
 {
     if (gameObject.name == "capsuleA") 
     {
         capsuleA = false;
         Debug.Log ("A passe faux");
     }
     if (gameObject.name == "capsuleB") 
     {
         capsuleB = false;
         Debug.Log ("B passe faux");
     }
     if (gameObject.name == "capsuleC") 
     {
         capsuleC = false;
         Debug.Log ("C passe faux");
     }
 }

}

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 hexagonius · Apr 02, 2017 at 12:35 PM 0
Share

the code is fine. either any of the colliders involved in the second and consecutive events are different from the first, or the collider moving is moved wrong. I guess the former is the case. pause the game and check prior to collision if everything is setup right

avatar image Asmode · Apr 02, 2017 at 01:56 PM 0
Share

Yeah i'd just figured out that my problem was from my other script (the one that make move my IA) and not from my collider check script. Sorry for being that stupid ^^"

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

99 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

Related Questions

Destroy object on hover? 1 Answer

Moving an Object Using a Trigger 0 Answers

Collider dosent detect trigger 0 Answers

OnTriggerEnter Issue - Collider problem 0 Answers

I'm trying to make a climbable ladder, but when I climb down, the character controller falls through the ground, Can anybody help me with this? 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