Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 maxjadin · Mar 05, 2014 at 02:27 AM · javascriptkill

Object wont kill player

Ok so i have a java script im useing for my codeing and it is sepost to kill the player but it is not im very new to codeing so i was wondering if anyone here can help me with my problem

heres my code im useing this is in java thank you in advance for any help

 function OnTriggerEnter(other : Collider){   //this function checks for the collision of the local Collider which is Trigger (i.e. field-like, and not rigid, objects can pass through the field, but will trigger the function)
       if(other.gameObject.name == "Player"){ //the function took an argument "other", it refers to a collider that is passing through the trigger field
              GameObject.Destory(other.gameObject); //using our keyword that refers to that external collider, it picks  the whole gameObject that somehow relates to that collider, that is, holds it.  We than destroy that gameObject
             for(var child : Transform in transform.gameObject){ //
                            GameObject.Destroy(child.gameObject);  //those three lines are only needed if you have children of the player objet that have to be removed
                 }                                                                            //otherwise, you can remove those 3 lines
              Debug.Log("Player was brutalized"); //write a message in a console that the player has r.i.p'ed
       }
     }
Comment
Add comment · Show 1
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 MrYOLO · Mar 05, 2014 at 03:34 AM 0
Share

First, add a debug message or break point in this function to make sure this function is excuted by Unity. And i also checked this: If obj is a GameObject it will destroy the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering. That means you dont need to destroy the child. And the time to destroy is after the update. Above all, I'm really doubt if OnTriggerEnter is called.

2 Replies

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

Answer by NoahConstable · Mar 05, 2014 at 04:17 AM

Hello Max, I assume you were trying to get the Player and its children objects to be destroyed if the Player hit the "kill" object. If this is true, then you really added too much code. I've modified yours to make it simpler and functional as well.

Here is the new code (put it on the "Kill" Trigger object):

 function OnTriggerEnter(other : Collider){
     if(other.gameObject.name == "Player"){
         GameObject.Destroy(other.gameObject);
         Debug.Log ("Player was brutalized");
     }
 }

Also, remember to tag your player as "Player".

Happy Coding!

Noah.

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 NoahConstable · Mar 05, 2014 at 04:22 AM 0
Share

I've decided to elaborate my script in the comment section

 //If our "$$anonymous$$ill" trigger object hits an object
 function OnTriggerEnter(other : Collider){
         //If that object is tagged as "Player"
     if(other.gameObject.name == "Player"){
                 //Destroy the player and all of its children
         GameObject.Destroy(other.gameObject);
                 //Print in the Debug Log, "Player was brutalized"
         Debug.Log ("Player was brutalized");
     }
 }

If you need help with anything else, just ask. If this fixed your problem, please mark your problem as solved, and mark my answer as correct. That way others who come here will know it is correct.

avatar image maxjadin · Mar 05, 2014 at 08:48 PM 0
Share

Thank you your awenser helped me alot it now works thanks again :D

avatar image maxjadin · Mar 05, 2014 at 08:50 PM 0
Share

im haveing another problem im posting it now if you have time it would be nice if you can help

avatar image
0

Answer by cartersupergames · Sep 12, 2021 at 08:36 PM

@maxjadin just use this script: OnCollision Destroy(GameObject Player) or use OnCollision Teleport(GameObject Player) 65.67465 74.73556 875.8736567 the random numbers are going to be the X, Y, and Z positions

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

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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

RPC kill counter 1 Answer

Realtime Turn Based game, random movement? 0 Answers

How to differentiate between prefabs on collision. 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