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 /
avatar image
0
Question by $$anonymous$$ · Jun 17, 2018 at 01:30 PM · 2d gamecollider2dtriggerscollision2d2d platformer

How to activate all GameObjects named ,,GroundCollider'' by touching ,,GroundTriggerCollider'' and deactivating when no longer touching ''GroundCollider"?

The Object I refer to as ,,GroundCollider'' is a Physics Collider and ,,GroundTriggerCollider'' is a Trigger Collider.

alt text Sorry. I overlooked Something while making the Visualization: In Panel 3, it's supposed to spell: ,,...and the Player doesn't fall through.''

unbenannt.png (110.2 kB)
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 Bunny83 · Jun 17, 2018 at 05:01 PM 0
Share

Too unspecific. Do you mean when no longer touching the GroundTriggerCollider or GroundCollider? In general you would simply activating them when you get the OnTriggerEnter and you deactivate them when you get the OnTriggerExit callback. With which part do you have problems? Finding / referencing the colliders you want to activate / deactivate? Getting the callbacks to properly activating deactivating the objects? What have you tried so far? Show the current state of your code.

avatar image $$anonymous$$ Bunny83 · Jun 19, 2018 at 01:12 PM 0
Share

I added a Illustration to make the Question as Specific as I could. ( ͡° ͜ʖ ͡°)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ppiotrsz109 · Jun 19, 2018 at 03:55 PM

You have to create static bool in one class which will contain info about, does it have to activate. In separate script you add OnTriggerEnter and OnTriggerExit and in another case OnCollisionEnter and OnCollisionExit, and one bool to select if it's GroundTriggerCollider or GroundCollider.
Than just based static bool you just get all objects in scene using GameObject.FindObjectsOfType() and using System.Linq you use method find, where you select that x.name = "GroundCollider".
If you have any questions, write comment.

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Jun 22, 2018 at 04:04 PM 0
Share

Sorry, but It's not specific enough.

How exactly is the Script written, that you mean?

avatar image ppiotrsz109 · Jun 24, 2018 at 04:47 PM 0
Share

Try like this: using UnityEngine; using System.Linq;

 public class Collider$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
 public static bool GroundTriggerColliderTouching= false;
 public static bool GroundColliderTouching = false;
 GameObject[] colliders;
 
 void Awake(){
 colliders = GameObject.FindObjectsOfType<GameObject>().Where(x => x.name.Contains("GroundCollider"));
 }
 
 void FixedUpdate(){
 if(GroundTriggerColliderTouching){
 foreach(var item in colliders){
 item.SetActive(true);
 }
 if(!GroundColliderTouching)
 foreach(var item in colliders){
 item.SetActive(false);
 }
 }
 }
 
 }

And now code for GroundTriggerCollider: using UnityEngine;

 public class GroundTriggerCollider : $$anonymous$$onoBehaviour {
 
 void OnTriggerEnter(Colider other){
 Collider$$anonymous$$anager.GroundTriggerColliderTouching = true;
 }
 
 void OnTriggerExit(Colider other){
 Collider$$anonymous$$anager.GroundTriggerColliderTouching = false;
 }
 
 }

And here the GroundCollider : using UnityEngine;

 public class GroundCollider : $$anonymous$$onoBehaviour {
 void OnCollisionEnter(Collision collision)
 {
 Collider$$anonymous$$anager.GroundColliderTouching = true;
 }
 void OnCollisionExit(Collision collision)
 {
 Collider$$anonymous$$anager.GroundColliderTouching = false;
 }
 }

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

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

Platform Effector 2D One Way, not working as expected 0 Answers

Comparing the value of a peg to its neighboring pegs' values 0 Answers

How do I make a bridge in game over an existing collision? 0 Answers

Trigger 2D (another gameObject) 4 Answers

Setting a Prefab Clone as the Child of another Object on Collision (2D) 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