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 Topthink · Mar 25, 2018 at 06:22 PM · script.inspectorcolliderscollisions

Instantiated Object Not "Colliding" as Expected.

I instantiate five to ten objects from the same prefab. These objects move down a road/trail and eventually pass through a wall (invisible, just there to detect passage). I have a "Counter" that is supposed to increment once each time one of my prefab objects pass through the wall.

The prefab objects have a rigidbody (for physics/movement) and a collider. My invisible wall has a collider.

No matter what I do, I can't get the Counter to add up to more than one (I accidentally got it to add up to two for a short period of time but can't even get it to do that now). I'm trying to figure out what my Inspector settings need to be to get my Counter to increment properly...it's obviously working a teenie bit or it would never get to "1" at all. Hmmmm.

Here's my OnTrigger code:

     void OnTriggerEnter(Collider col)
     {
         if (col.gameObject.tag=="Finish")
         {
             Counter01++;
             Debug.Log("Bingo  " + Counter01);
         }
     }
Comment
Add comment · Show 4
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 Topthink · Mar 25, 2018 at 07:06 PM 0
Share

I've split off my "OnTrigger..." portion of the script to its own script and I'm positioning that on different objects to test if that is the problem...I'm putting it on the "finish" cube and I'm putting it on the Instantiated objects, etc. in different combinations.

I'm throwing all my brain cells at this right now (that's probably my main problem right there ;) ) but I'm not having much luck resolving this matter.

I'll keep at it.

avatar image Topthink · Mar 25, 2018 at 07:21 PM 0
Share

I think I'm getting it narrowed down, at least I have it printing "1" over and over (once for each object that passes through). But at one point, it was printing "1" continuously: 999+ times in the console.

$$anonymous$$aybe I haven't had enough coffee yet. Probably something simple that I'm overlooking for some reason.

avatar image Topthink · Mar 25, 2018 at 08:51 PM 0
Share

Seems to be colliding, my Debug.Log will print one time for each instantiated racer...so it's detecting the collision. It's just not incrementing my counter. Hmmmm. I'll post up some code here in a moment. I had to reboot my computer to see if that made any sort of difference. Getting program up now.

avatar image Topthink · Mar 25, 2018 at 08:57 PM 0
Share

Here's my script as last written. I've rewritten it many ways. Not getting anything to work. The following code will print (Debug.Log) "101" one time for each instantiated object that crosses the "finish" line. So it is detecting the objects as they cross, but it is not incrementing my counter. Hmmmm.

 public class TriggerScript : $$anonymous$$onoBehaviour 
 {
     private int zCount02=100;
     void start()
     {
         zCount02 = 200;
     }
     void OnTriggerEnter(Collider col)
     {
         if (col.gameObject.tag=="Finish")
         {
             RacerFinished ();
         }
     }
     public void RacerFinished()
     {
         zCount02++;
         Debug.Log ("Done at Last  " + zCount02);
     }
 }
 
 
 

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Topthink · Mar 25, 2018 at 09:28 PM

I figured it out folks. Well, at least I figured a solution that works. I just made it a static variable over on yonder script and then just increment and decrement as necessary from wherever necessary. It will be fine that way because it's only used for a single purpose and will be the same no matter where or when it is used elsewhere.

Thank you for any consideration.

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 NoMoneys · Mar 25, 2018 at 06:50 PM

What is "Counter01", a global variable? If it is you might wanna check if you're setting it anywhere else in your code.

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 Topthink · Mar 25, 2018 at 07:03 PM 0
Share

Thanks. Good question. It's not a global/static variable.

I've tested it as a public and private variable in different locations in my scripts just in case my problem was with that. Same results. It's picking up the one collision (and in the one case, the two collisions) so I'm pretty sure that is not the problem.

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

81 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

Related Questions

How to make a particle system play on trigger with another box collider 1 Answer

Flying Controls Collision Issues 0 Answers

How to do static collision checks? 1 Answer

Why there is no Collider.IsTouching(...) ? 2 Answers

More realistic physics? 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