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 oliver-jones · Mar 31, 2011 at 04:28 PM · collisioncollidertag

Help With Colliders

Hello,

I have a prefab of a turret (which has its own collider - trigger), I also have a game boundary which is just a trigger collider (tagged GameBoundary).

I basically want a boolean to be true if turret touches game boundary.

EG:

if(turretCollider collides with collider tagged GameBoundary){
   madeUpBoolean = true;
}

So if the turret makes contact with the game boundary: madeUpBoolean = true

How would one do that?

Thanks

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
1
Best Answer

Answer by Justin Warner · Mar 31, 2011 at 04:42 PM

You'd use the OnCollisionEnter, and then take what is colliding with it, and check the tag of that object, and if it's equal, than do it:

function OnCollisionEnter(collision : Collision) {
    if(collision.gameObject.tag == "GameBoundary")
    {
        madeUpBoolean = true;
    }
}
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 oliver-jones · Apr 01, 2011 at 10:52 AM 0
Share

but the function OnCollision has to be on an object that is getting collided right? I have a script that isnt attached to either of the objects. So I want to get the info from the turretCollider, and the gameBoundaryCollider

avatar image Justin Warner · Apr 01, 2011 at 11:43 AM 0
Share

Not following... If you do this, you can access whatever variables (Assu$$anonymous$$g madeUpBoolean) from another script with.... I don't know, I always used broadcast message which kind of sucks, I think GetComponent and you can get a script of an object... And then use it accordingly. So then put the script on the turret, and on the main script, just access it...? Would that work for you?

avatar image
0

Answer by e-bonneville · Mar 31, 2011 at 04:52 PM

Put this on your turret:

JS:

function OnCollisionEnter(col : Collision) {
    if(col.collider.GameObject.CompareTag("GameBoundary")) {
        madeUpBoolean = true;
    }
}

C#:

void OnCollisionEnter(Collision col) {
    if(col.collider.GameObject.CompareTag("GameBoundary")) {
        madeUpBoolean = true;
    }
}

Please note that the above code is untested and may contain 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
avatar image
0

Answer by Justin Warner 1 · Mar 31, 2011 at 04:53 PM

Someone can delete this.........

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

What's wrong with OnCollisionEnter? 2 Answers

OnCollision Script... 2 Answers

A limit to the number of tags? 2 Answers

My script says object is not colliding with the tag! But it is! 1 Answer

Collision Issue 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