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
1
Question by stford 1 · Nov 03, 2010 at 07:00 PM · tagshit

hit.gameObject.tag

ok im using hit tags and the first one works but the second one just freezes so if i tag the sheep as "Bunny" they burst in to a red paritcal cloud but the sheep dont un less I use the Bunny tag but ....well I need more blood for the sheep! so I want to run a bigger partial explosion.

var particle : GameObject; var particleSheep : GameObject;

function OnControllerColliderHit( hit: ControllerColliderHit) { Debug.Log("hit Call"); if(hit.gameObject.tag == "Bunny") { Debug.Log("Bunny hit"); // create the instance of the prefab var clonedParticle : GameObject = Instantiate(particle, transform.position, transform.rotation);

     clonedParticle.particleEmitter.emit = true; // tell it to emit

     Destroy(clonedParticle, 4); //destroy the particle in 4 seconds
     Destroy(hit.gameObject); 
 }
 else if(hit.gameObject.tag == "Sheep") { 
     Debug.Log("Sheep hit");
     // create the instance of the prefab
     var clonedParticleSheep : GameObject = Instantiate(particleSheep, 
                                                        transform.position, 
                                                        transform.rotation);

     clonedParticleSheep.particleEmitter.emit = true; // tell it to emit

     Destroy(clonedParticleSheep, 4);//destroy the particle in 4 seconds
     Destroy(hit.gameObject); 
 }

}

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
0

Answer by Atnas1010 · Nov 03, 2010 at 07:08 PM

Since you say it works when you tag the sheep "Bunny", the colliders must be set up properly. The only thing I can see that could be wrong would be that you have not tagged your sheep, "Sheep" (with a capital S) since that is what you compare the tag to.

If that doesn't solve the problem, then try adding an "else" after your sheep's "if", such as this

else 
    Debug.Log(hit.gameObject.tag);

And check your console, to see if it gets printed (and what it prints)

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 skovacs1 · Nov 04, 2010 at 04:55 PM 0
Share

@Atnas - This doesn't actually tell the op what's happening. You should be clear in telling them that the only reason you see that the if(hit.gameObject.tag == "Sheep") would fail is if they were not properly tagged "Sheep".

avatar image Atnas1010 · Nov 04, 2010 at 05:11 PM 0
Share

I edited my answer. It might not be the same standard as yours, but I hope it is acceptable

avatar image
0

Answer by skovacs1 · Nov 04, 2010 at 05:03 PM

There are only 2 reasons that I see that would cause your Debug("Sheep Hit") not to happen:

  1. The sheep are not properly tagged Sheep
  2. The sheep are not generating an OnControllerColliderHit

To address number 1. please verify that all instances of your sheep are properly tagged exactly Sheep with the exact case and spelling as you are checking for in your if statement.

To address number 2. please verify that your sheep have colliders that are setup properly. It seems that since you are colliding with your bunnies that your character controller capsule and movement must be setup correctly, but all the same, please ensure that neither of these is preventing collisions somehow. Also, please make sure that your sheep are on an appropriate layer for which Physics interaction with the layer the CharacterController is on has not been disabled.

If your Debug is printing, please rephrase the question to describe what exactly is not happening.

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

How does my raycast work? 1 Answer

Are tag settings passed down from Game Object parent to mesh child? 1 Answer

Accessing all GameObjects with a certain tag 1 Answer

Trouble editing tags 1 Answer

I need my AI to attack any object who is tagged with a specific tag like let's say "enemies".Can someone help me?.I tryed everything and nothing seems to work. 3 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