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 Headstone7 · Jan 08, 2014 at 03:26 PM · triggerdeathempty game object

How to "Stop my character from dying for no reason"?

Hi, i recently figured out a way to make my character die if hit on the head by a falling object that needs to be "not trigger" to prevent it from falling through the ground.

Unfortunately, my character, just sometimes, dies for no apparent reason (or for a reason i can't recognice) and i guess i made some mistake with this script, have a look!


 function Start () {
 
 }
 
 function Update () {
 
 
 }
 
 
 function OnTriggerEnter (otherObject: Collider)  {
 if((GameObject.Find("CubePrefab(Clone)")) ){
 
 
       
          Destroy(GameObject.Find("First Person Controller"));


I'm completely a newbie with scripting so don't go mad if you read something that is just stupid to you ^^

I noticed that if i place the empty object this script is on, right over my character, he istantly dies, so i moved it a bit far, not too much, and i guess this could give you some kind of help with helping me solve the problem :)

So, what can i do to solve my problem?

Thanks everyone :D

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
Best Answer

Answer by raimon.massanet · Jan 08, 2014 at 03:38 PM

You are destroying your player if it collides with anything and there is a "CubePrefab(Clone)" object in the scene. I don't think that's what you intend to do.

Instead, you could assign a tag to the falling object and then:

 function OnTriggerEnter (otherObject: Collider)
 {
   if(otherObject.gameObject.tag == "FallingObject" )
   {
     Destroy(GameObject.Find("First Person Controller"));
   }
 }

On the other hand, GameObject.Find is a very expensive function that should be avoided. Declare a public GameObject variable and assign the first person controller game object from the inspector.

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 Headstone7 · Jan 08, 2014 at 03:49 PM 0
Share

Thanks mate! This totally worked out for my little character, that is now grateful with you, kind person :3 I realized the point of .Find when i found out that noone was using that "system" and i'm trying to think on how to make that work differently, but that's not my main problem atm, will be as soon as i'll have solved many other problems ahahah ^^

avatar image raimon.massanet · Jan 08, 2014 at 04:03 PM 0
Share

You're welcome :-)

avatar image
0

Answer by tanoshimi · Jan 08, 2014 at 03:34 PM

I'm going to add some comments to your code to help you understand the logic of what's going on...:

 // This function gets called every time the object to which this script is attached
 // enters any trigger
 function OnTriggerEnter (otherObject: Collider) {
 
     // If there is any object anywhere is the scene called "CubePrefab(Clone)"
     if((GameObject.Find("CubePrefab(Clone)")) ){
  
         // Find and destroy the object called "First Person Controller"     
         Destroy(GameObject.Find("First Person Controller"));
     }
 }

... is that really what you meant?

Comment
Add comment · Show 1 · 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 Headstone7 · Jan 08, 2014 at 03:46 PM 0
Share

Well, your answer pretty much clarified me the point! So thank you ^^ Unluckily raimon gave me the thing that made me solve the issue and so i gave him the "right answer", sorry bro :D I wish i could accept both of your answers :(

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

20 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 avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to add a Kinematic Rigidbody to a cube? 1 Answer

Detect collision/trigger between two body without rigidbody? 3 Answers

need help with trigger 1 Answer

Animation plays on when colliding with a trigger 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