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 cipherr · Nov 14, 2014 at 06:31 AM · collisiongameobjecttrigger

Checking trigger/collision of another gameobject separate from the one the script is on

Not sure how to word this exactly, so I'll just give a sample of code. I'm just wondering if there's a way to do this without making 2 scripts. I have a simple AI that paths around, and I want it to chase the player when he walks into a collision zone. So this script would be on the enemy

 void onTriggerEnter(Collider coll){
         if(coll.gameObject == player){
                //do stuff
          }
      
          //so is there a way to do something like this, in this script?
          it(chaseArea.coll.gameObject == player){
                //do different stuff
                //basically checking to see if someone collided with the chaseArea GO in the same script
          }
 }

Is there a simple solution to this? Or do I just need to make another script and reference it? I've been using unity for a while and I've never managed to figure this one out.

Thanks!

Comment
Add comment · Show 3
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 AlwaysSunny · Nov 14, 2014 at 06:30 AM 0
Share

Not completely sure I understand the question.

Calls to enter, stay, and exit methods for triggers and collisions are only received by the objects with these methods in their scripts. For any given interaction, you have access to both parties involved. There can be no third party involved.

avatar image robertbu · Nov 14, 2014 at 06:31 AM 0
Share

Note that OnTriggerEnter() starts with an upper case 'O'.

avatar image cipherr · Nov 14, 2014 at 07:51 AM 0
Share

@ AlwaysSunny - I think you pretty much answered my question anyways, but here's another wording. EnemyScript is on EnemyGO. ChaseArea is a GO declared in the EnemyScript. I was asking if I could check if something collided with ChaseArea in the EnemyGO script, without doing it separately in a new script on the ChaseArea game object

@ Robertbu - Okay I know that, this script isn't copied from anything, just something I wrote in the chat box to illustrate it. $$anonymous$$y mistake

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AngryBurritoCoder · Nov 14, 2014 at 10:00 AM

Why not just make one script and attach it to different objects that represent the zones, i do not know why you need different scripts ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

If gameObject's center passes through a trigger? 1 Answer

Mission Objectives 1 Answer

Trouble Descaling 2D object 1 Answer

Collecting Array items in order 1 Answer

Sphere and Cube collision won't work,Sphere vs Cube collision won't work 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