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 /
avatar image
0
Question by ROM · Aug 04, 2010 at 04:42 PM · collisioncollidertriggerenter

Collision between objects?

I'm currently doing collisions using the following code:

function OnTriggerEnter (boxCollider : Collider) {
    if(boxCollider.collider.name == "Box"){
        hittingVar = true;
    }
}

This is added to an object (A) and detects collisions with another object (B). However now what I want to do is to look at collisions between A and B from a third object (C). This needs to be extremely precise and up to date so basically I'm wondering if there is a piece of code I could use to say "If A intersects B then do this" that I could apply to C. I don't want to simply use variables and get them from another script because as I say it needs to be extremely up to date and there seems to be a small amount of lag when i do that :).

Thanks in advance!

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

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

Answer by Wolfram · Aug 04, 2010 at 05:04 PM

There should be no lag unless you search object C within your OnTriggerEnter() function everytime. Instead, search your object C in Awake() or Start() once (or directly assign it in the Inspector), and then refer to that variable. Then modify your script to call one of C's functions:

var objC : ObjectCScript;

function Awake () { objC = Find("ObjectC's name").GetComponent(ObjectCScript); }

function OnTriggerEnter (boxCollider : Collider) { if(boxCollider.collider.name == "Box"){ objC.DetectedCollision(); } }

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
1

Answer by Extrakun · Aug 04, 2010 at 05:03 PM

A couple of options.

You can set a reference to your third object

public subject:ComponentC

function OnTriggerEnter (boxCollider : Collider) { if(boxCollider.collider.name == "Box"){ hittingVar = true; subject.NotifyCollision(this.gameObject, boxCollider.gameObject) }

}

You can use send message

function OnTriggerEnter (boxCollider : Collider) {
     if(boxCollider.collider.name == "Box"){
        hittingVar = true;
        GameObject.FindWithTag("Subject").SendMessage("NotifyCollision");
    }

Setting a variable directly on C should be faster than any of those method, IMHO, but ugly and prone to errors.

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

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

No one has followed this question yet.

Related Questions

Overlap point of 2 kinematic colliders 1 Answer

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

Check if trigger is occupied 1 Answer

Triggering platform animation on colliding with Button 0 Answers

Prevent shooting when gun is inside wall 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