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 blackshtormx · Nov 17, 2013 at 12:31 PM · animationspeedlife

WHY IT ISNT WORKING?!

Script is working fine, soldier is destroying its self if i am hitting a car to him, but it isn't working if i shoot him with bullets("Sphere"). (soldier is colliding bullets) here is script i am using:

 var speed:float=2;
 var life = 20;
 function Update () {
 
 animation.Play();
 transform.Translate(Vector3.forward * speed * Time.deltaTime);
 
  
 }
 
 
 function OnCollisionEnter(theCollision : Collision){
  if(theCollision.gameObject.name == "car"){
   Destroy(gameObject);
  }
  
  if(theCollision.gameObject.name == "Sphere(clone)")
  {
   life -= 20;
   
    if (life <= 0)
   {
   Destroy(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 fafase · Nov 17, 2013 at 12:33 PM

I think clone should be Clone but to prevent this kind of problem, you should tag your object and use the tag instead.

 function OnCollisionEnter(theCollision : Collision){
    if(theCollision.gameObject.name == "car"){
       Destroy(gameObject);
     }
  
     if(theCollision.gameObject.name == "Projectile"){
        life -= 20;
        // Rest
     }
 }
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 tanoshimi · Nov 17, 2013 at 02:46 PM

BECAUSE CORRECT CAPITALISATION IS IMPORTANT.

As you've already discovered:

 if(theCollision.gameObject.name == "car"){ ... }

is working. But:

 if(theCollision.gameObject.name == "Sphere(clone)") {...}

is not. Look carefully at the names of clones instantiated in your hierarchy and you'll see why not.

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 fafase · Nov 17, 2013 at 03:10 PM 0
Share

If you do not feel like answering don't bother. This is not bringing anything to the thread. I think your karma allows you to edit content, just do so and place a comment. This "answer" would deserve a great deal of downvote. Same here, I could just delete your answer and not say anything.

avatar image tanoshimi · Nov 17, 2013 at 03:37 PM 0
Share

Fair comment, and you're right to point out that my "answer" is somewhat obtuse. However, it does actually point out to the OP the cause of their error. You don't get better at program$$anonymous$$g by having all your errors corrected and handed to you on a plate. You get better at program$$anonymous$$g by getting assistance in knowing what to look for in order to solve your own problems....

Nevertheless, I'll amend to make it somewhat clearer.

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

18 People are following this question.

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

Related Questions

Speed button for animations? 2 Answers

Not Run while Aiming; Slope Terrain Making Object Faster 0 Answers

animation speed no work 1 Answer

Can I make animations snap to a frame? 1 Answer

How can I get animation state speed in code 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