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 Ampler Games · Aug 22, 2012 at 03:39 AM · collisionlevelreset

reset level on collision

Ok, so what I want to do is to make it that when ONLY the player hits a specific object it reset that level. I have tried many scripts for this but can't seem to be able to get any of them to work, they will either reset the level when any object hits it or they just don't do anything.

Please help

-Ampler Games

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

3 Replies

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

Answer by aldonaletto · Aug 22, 2012 at 04:35 AM

Usually, you should check the player tag or name in the collision code - but be aware that there are several combinations (rigidbody hits something, character controller hits a collider, character controller enters a trigger) with different procedures.
The most common case is a character controller entering a trigger (trigger script):

function OnTriggerEnter(other: Collider){
  if (other.tag = "Player"){
    Application.LoadLevel(Application.loadedLevel);
  }
}
Another possibility is a character controller colliding with a collider - in this case the event is sent to the character controller script, thus you must check the other object's tag or name:

function OnControllerColliderHit(hit: ControllerColliderHit){
  if (hit.transform.name == "ResetGameObject"){ // compare the object name
    Application.LoadLevel(Application.loadedLevel);
  }
}
Finally, if the character is a rigidbody, use OnCollisionEnter in the other object's script:

function OnCollisionEnter(col: Collision){
  if (col.transform.tag == "Player"){
    Application.LoadLevel(Application.loadedLevel);
  }
}

NOTE: Remember to set the correct tag or name in the appropriate object (target object in the second case, player in the 1st and 3rd)

Comment
Add comment · Show 4 · 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 Ampler Games · Aug 29, 2012 at 02:59 AM 0
Share

Thanks heaps, I have been trying to get this to work for a while. Now it works

avatar image marnix2001 · Nov 25, 2015 at 04:04 PM 0
Share

help i have lava with the tag lava i want if the player with the tag player hit the lava that scene restart please help

avatar image marnix2001 · Nov 26, 2015 at 09:59 AM 0
Share

help i got lava with the tag lava and i want if the player touch the lava that scene restart can you help i us unity 5

avatar image fabiobatu72 marnix2001 · May 07, 2018 at 11:58 AM 0
Share

u change the tag from "player" to "lava"

avatar image
0

Answer by help00686 · Nov 14, 2018 at 09:32 PM

Where does this code go please

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 marnix2001 · Nov 14, 2018 at 09:38 PM 0
Share

if u use this one function OnTriggerEnter(other: Collider){ if (other.tag = "Player"){ Application.LoadLevel(Application.loadedLevel); }}

then u need to place it on the object that can kill the player.... make sure to give the player object the tag Player

avatar image
0

Answer by NaturedOne · May 05, 2019 at 02:56 AM

If anyone else runs into this,

 Application.LoadLevel(int);

is obsolete, you'll want to use:

 SceneManager.LoadScene



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

12 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

Related Questions

Multiple Cars not working 1 Answer

Trying to animate on collision, Help Please. 0 Answers

Script help please 1 Answer

Analysing player metrics help 0 Answers

On Collision, Create a Cube? 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