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 /
  • Help Room /
avatar image
0
Question by rsnrslt · Nov 04, 2021 at 11:30 AM · unity 5unity 5.2

Get collider and list it,Get Collider and List it

Hello everyone. What I want to do is; Putting 4 tire colliders in one area but counting down the tires and glowing green when you put the last tire in. I can turn the field green, but the colliders turn green as soon as they touch each other. I want the tires to glow green when they're all in. I would be very happy if anyone can help.

  private Color m_oldColor = Color.white;

  private void OnTriggerEnter(Collider other)
  {    
      Renderer renderer = GetComponent<Renderer>();
 
      m_oldColor = renderer.material.color;
      renderer.material.color = Color.green;
  }
 
  private void OnTriggerExit(Collider other)
  {
      Renderer renderer = GetComponent<Renderer>();
      renderer.material.color = m_oldColor;
  }


the code i made to turn it green

but i cant get the colliders from the car controller script.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Senetry · Nov 04, 2021 at 07:41 PM

Hello have you considered adding tag to your tires or vehicle or adding tires on layer which do not collide with itself? There is this setting in project setting alt text

You can create and set layer here alt text

It is edit/project settings/physics 2d and Layer collision matrix you can set there what should collide and what not


screenshot-2021-11-04-at-203653.png (383.0 kB)
screenshot-2021-11-04-at-203801.png (28.3 kB)
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 Senetry · Nov 04, 2021 at 08:15 PM 0
Share

Sorry I made reply for 2D but you can do same thing in 3D just choose Physics instead of Physics 2D

avatar image
0

Answer by rsnrslt · Nov 05, 2021 at 10:17 PM

I'm sorry for asking stupid questions because I'm just getting started. . What I want to do is; All 4 tires glow green when they enter an area. I tried layers but no result. my tires have colliders and transforms. I need to use the count variable so that 4 tires enter the region I have determined. I don't know how to do this

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 Senetry · Nov 06, 2021 at 01:15 PM 0
Share

@rsnrslt Can you post code you use for count? Also your new layer settings. And there are no stupid questions everybody starts somewhere.

Well you need to add static int variable which will increase when you hit collider of your basket.

Something like:

     private Color m_oldColor = Color.white;
         private static int count = 0;
         private void OnTriggerEnter(Collider other)
         {
             count++;
         }
 


  private void OnTriggerStay(Collider other)
     {
         Renderer renderer = GetComponent<Renderer>();
         if (count == 4)
         {
             m_oldColor = renderer.material.color;
             renderer.material.color = Color.green;
         }
         else
         {
             renderer.material.color = m_oldColor;
         }
 
     }

 private void OnTriggerExit(Collider other)
     {
         count--;
     }

But to have layers set correctly is also important so it do no get called when it hits everything. Sorry I had to add lines to separate code because my browser do not format it correctly.

avatar image rsnrslt Senetry · Nov 09, 2021 at 05:33 PM 0
Share

[SerializeField] private WheelCollider frontLeftWheelCollider; [SerializeField] private WheelCollider frontRightWheelCollider; [SerializeField] private WheelCollider rearLeftWheelCollider; [SerializeField] private WheelCollider rearRightWheelCollider;

these are colliders inside the carController script

I changed the layers and tags of my car's colliders. (tag = wheel1, layer = wheel)

(tag of parking side = square) , (layer = area)

What I want to do is to assign the colliders I wrote to the list. Then checking the list one by one to see if it goes inside the field. When I used the code you wrote and changed the layers, I still did not get a result.

the script is inside the parking area object(triggerScript)

  • List item

avatar image
0

Answer by abadanoglu · Nov 07, 2021 at 02:50 PM

For those who are interested, the link of the package file

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 Senetry · Nov 07, 2021 at 04:57 PM 0
Share

Is this related to the question? I do not get it.

avatar image abadanoglu · Nov 07, 2021 at 09:10 PM 0
Share

I made a mistake. I thought I added the file for the question I added myself. I am so sorry.

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

271 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Physical Based Lighting/shadow Augmented Reality 1 Answer

Google Cardboard for Unity renders only one light source 1 Answer

Do I need to reconfigure materials for unity 2017? 1 Answer

Can I edit and add code after Unity3d project is ported to IOS? 0 Answers

How to hide gameobjects by layers? 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