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 hariprasadh10792 · Nov 21, 2011 at 01:01 PM · colliderplatformerdeathoncollision

Crushing Character

I am making a platform game, where the player can get crushed if the moving platform collides on the player when the player is on the floor, So i am using a code

 function OnCollisionEnter(collision : Collision) 

{

if((collision.gameObject.name == "Crushed Death") && (collision.gameObject.name == "Moving Platform"))

{

     Destroy(obj.gameObject);
 }    

}

function Update()

{
}

The code doesnt seem to be working!! And I attach this script to the player!

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
1

Answer by wccrawford · Nov 21, 2011 at 03:06 PM

The name of the object cannot be more than 1 thing at a time, so your code can never evaluate to true.

Comment
Add comment · Show 3 · 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 LegionIsTaken · Nov 21, 2011 at 03:39 PM 0
Share

I don't think you are right(please correct me if I am wrong), since the name is a string, it will just look for a string matching it regardless of length and such.

I may be wrong, though.

avatar image hariprasadh10792 · Nov 21, 2011 at 03:43 PM 0
Share

Is there any way I can achieve the crush mechanic?

avatar image wccrawford · Nov 21, 2011 at 04:03 PM 1
Share

@Legion He has checked that collision.gameObject.name equals both "Crushed Death" and "$$anonymous$$oving Platform". Since it cannot be both things at once, it can't work.

@hariprasadh10792 What you're looking to do is check that you're touching both the platform and the whatever is crushing the player from above. How you do that will depend on your other code. If you're using the built-in character controller and physics, you can probably checked for a collision with the crushing thing, and check if the isGrounded flag for the character controller.

avatar image
0

Answer by FLASHDENMARK · Nov 21, 2011 at 03:48 PM

 function OnCollisionEnter(collision : Collision) {
 if(collision.gameObject.name == "Crushed Death" && collision.gameObject.name == "Moving Platform"){
     Destroy(gameObject);
     }   
 }

There were a few things that may be wrong.

  • (Disclaimer: the method you used may be working right, but there is no really need for it). When you clarified your if statement you used double brackets E.G if((blahh) && (blah)). There is no need for "double bracketing" in your case. You could simply just write if(blah && blah)(with out the double brackets)

  • And what is "obj.gameObject"? Are you sure you are not supposed to use gameObject only?

Those were just suggestions that may be wrong. I cannot say for sure with the current information at hand.

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 hariprasadh10792 · Nov 22, 2011 at 12:02 PM 0
Share

obj is a var game object! So i wanted the script to mean something like if the obj is touching the floor and crushed death at the same time the obj gets destroyed!

avatar image hariprasadh10792 · Nov 22, 2011 at 12:03 PM 0
Share

and i also tried putting in the code you gave it doesnt seem to be working for some reason! The script also manages to compile without any errors!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Triggering platform animation on colliding with Button 0 Answers

Yield Continuous Death 1 Answer

grouped edge colliders causing strange effects to physics 2d bodies 1 Answer

Platforms again.. Working but.. 0 Answers

Controller2D - Raycast : Collider sometimes pass through platform 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