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 Romano185 · Apr 05, 2012 at 06:03 PM · gameobjectcollidertriggertag

Trigger can't see the enemy

Hi everybody

I've made a script I'm planning to use for attacking the enemy. I tagged 1 kind of enemy with the tag Enemy and another one with the tag Enemy1. Those enemies also both have a Sphere Collider attached to them. I just want the script to store the variable of the enemy entering the trigger, but it doesn't work.

 var enemy : GameObject;
 
 
 function OnTriggerEnter(trigger : Collider){
 if (trigger.tag ==("Enemy") || trigger.tag == ("Enemy1")){
 enemy = trigger.gameObject;
 }
 }

But it doesn't work. Why?

Please help me!

Comment
Add comment · Show 2
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 fafase · Apr 05, 2012 at 06:14 PM 0
Share

There is no need for 2 different tags since you do the same thing, just tag both as Enemy Also, what is enemy = trigger.gameObject; supposed to do?

var enemy : GameObject;

 function OnTriggerEnter(trigger : Collider){
      if (trigger.gameObject.tag ==("Enemy") {
 // do something here
 }
 }
avatar image Eric5h5 · Apr 05, 2012 at 08:57 PM 0
Share

You don't write "solved" in the title, you accept the correct answer by clicking the checkbox. Also don't post comments as answers.

2 Replies

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

Answer by rutter · Apr 05, 2012 at 06:48 PM

  • Do both objects have colliders attached?

  • Does at least one object have a rigidbody attached?

  • Is at least one of the colliders a trigger?

You might check if you're getting a call to OnTriggerEnter() at all, with a quick debug statement:

 Debug.Log("I was called!");

If you don't see that log, you know your collision isn't quite set up right.

If you do see that log, you know that either your script's logic isn't quite set up right, or that your objects aren't configured in the way that your script expects.

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 dklompmaker · Apr 05, 2012 at 07:07 PM

Hello,

First make sure that one of the objects has a Rigidbody component added to it. (Preferably the player object). Try that and see if that works. Also, double check that the Sphere Collider has the "Is trigger" check box checked.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Reaching a gameobject from its collider 3 Answers

Multiple Colliders Trigger problem 2 Answers

Collision, tags, and triggers 1 Answer

I need help with triggers 1 Answer

Moving objects using raycasting? 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