Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed May 15 at 09:04 PM by Nakoru for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Nakoru · Aug 01, 2021 at 09:33 AM · collider2dontriggerenter2dchecking

Can you check again something that is already in the IsTrigger collider ?

Okay so, I'm making a C4 planting system, and I'm in the last part where the C4 detects a destroyableWall, checks if it's time to destroy it, and if, destroys it.

The script works well, detects the wall and the other script finishes his work with timeToDestroyWall = true. The thing is, my C4 code won't work, and it' surely due to the fact that the checking is done only one time (it's not an Update() function and it's litteraly in the name, "OnTriggerEnter2D")

So, now you have a better understanding of my problem, here's the question :

What alternative can I use instead of OnTriggerEnter2D that would keeps checking items inside the collider ?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class C4Manager : MonoBehaviour
 {
     public bool destroyableWall;
     public GameObject Inventory;
     public Inventory inventoryScript;
 
     public void Start()
     {
         Inventory inventoryScript = Inventory.GetComponent<Inventory>();
     }
 
     public void OnTriggerEnter2D(Collider2D other)
     {
         if(other.CompareTag("destroyableWall"))
         {
             destroyableWall = true;
 
             if (inventoryScript.timeToDestroyWall)
             {
                 Debug.Log("attempting destruction...");
                 Destroy(other);
             }
         }
     }
 }

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

2 Replies

  • Sort: 
avatar image
0

Answer by thomaslijohnson · Aug 01, 2021 at 09:37 AM

try using OnTriggerStay2D

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 rage_co · Aug 01, 2021 at 12:20 PM

Like @thomaslijohnson said, you can try using OnTriggerStay2D().....or you could go with the approach that you create a list of colliders and add the current collider in OnTriggerEnter to thag list and remove it in OnTriggerExit and when destroying the object...this is a much more flexible approach....you can also put a part of this in OnTriggerStay which will check if the list already contains the collider through list.Contains(collider)...and if not...add it to the list....minimising the chance of an unwanted bug or glitch

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

Follow this Question

Answers Answers and Comments

127 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 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

OnTriggerEnter2D works without being actually triggered. 0 Answers

Object is not colliding with wall colliders 0 Answers

OnTriggerEnter2D - am I getting it wrong? 2 Answers

OnTriggerEnter2D & OnCollisionEnter2D Not Responding 1 Answer

Unity 4.5 - OnTriggerExit2D 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