Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Tanglecat13 · Nov 25, 2015 at 02:29 AM · c#collisiontrigger

How do I create a script to reset a level when my Player comes into contact with an object?

I am trying to find or get help creating a script to reset the level when my Player is "killed" or comes into contact with a certain object I have little coding knowledge so please if you would be so kind to dumb down your answers Thank You

Comment
Add comment · Show 2
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 say_forever · Nov 25, 2015 at 03:11 AM 0
Share

Does "reset a level" mean changing Scene for you?

avatar image iwaldrop · Nov 25, 2015 at 03:34 AM 0
Share

I can't tell if you're asking about the unity API or a pattern to help you accomplish the task.

In general the unity script reference is a great resource for API stuff.

If you're asking about a pattern, I'd look into using the observer pattern. It will allow you to simply send out an event when an arbitrary action occurs. Other things 'observe' this event and react to it.

Using your example, you'd have a 'player died' event, and an observer that reacted to that by restarting the level. This kind of pattern makes it easy to change out what happens when the player dies by simply changing out what is observing the event.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by itsharshdeep · Nov 25, 2015 at 04:38 AM

Hello

Can you please tell me If you re-load the scene then it will solve your problem or not? Reload the scene will act like same as you entered the scene. Now you have to do like suppose if your player have health. Now you have to place the check whether/if the player has health 0. Then you will show the game over screen & on "Retry" or "Play Again" button the scene must be reload. With the line Application.LoadLevel("SceneName"); or Application.LoadLevel(Application.loadedLevel);

Now that was the one answer to your question. For the Region / specific area when player get in that area. There are different types of option to do this . It is basically depend upon the scene. But the most common one is to place the empty triggered collider which will tell you when the player enter in the region.

For that you have to write like :-

 void OnTriggerEnter(collider c){
    if ( c.transform.tag == "Player"){
        // Show game over screen here   
     }
 }
 
 
 void OnPlayAgainButton(){
       Application.LoadLevel(Application.loadedlevel);
    }
 

There is also one more solution of your question is to will track all the things of the objects, references in your game like player score, health , positions of the objects etc etc. and when the player get killed then you have to call the that Reset() method in which it will reset all the vales. This method is little hard as compared to the above one. Note - Rest all the approach vary with your requirement of the games/requirements.

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

43 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 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

OnTriggerEnter2D not working 1 Answer

Detect the objects staying on top of the Particles 0 Answers

How can I remove movement or camera rotation in one direction with a trigger 0 Answers

Applying force when colliding with several objects 1 Answer

How to have a game object register its OnTriggerEnter function? 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