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 favian13 · Oct 21, 2011 at 01:01 AM · levelreset

How to reset a level by collecting items?!?!

Hello, i need a script for when i collect a collectable object but when you collect all the object it resets the level. thanks!

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
3

Answer by Psychlade · Oct 21, 2011 at 07:52 AM

No one here is going to write up a script for you, but we can push you in the right direction. ;)

First, if you don't know how to do something so basic, I think you should get acquainted with the tutorials all over the internet. I'm on them everyday and just can't help myself. It's that fun once you get past the first few 'pits' of scripting. Not hard at all, just fun.

If your collecting gameObjects, let's say 10, I would assign a trigger to each of the them. This trigger would add 1 point to an integer variable and when you've collected all 10 gameObjects, you can do what was suggested in the selected answer here.

Here's the link for a good starting point for Triggers. Have fun!

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

Answer by ocularcash · Oct 21, 2011 at 08:10 AM

you really should learn to write code. It's alot easier to get help from ppl if you type what you understand and someone can just adjust it. but this is an easy script so i'll give you a simple code. There's a bunch of different ways to do this but the main ways are to make the objects inactive (invisible) which you can turn back on at any given time, like if you have to get it from the same point more than once, or call a destroy function which takes the object completely out. Coding is very easy to understand. How you would say it is pretty much how you write it.

var CollectedObjects : int = 0;

var Coin1 : GameObject;

var Coin2 : GameObject;

function Update()

{

    if(CollectedObjects >= 2)

    {

             Application.LoadLevel(1);

             CollectedObjects -= 2;

    }

}

function OnControllerColliderHit (hit : ControllerColliderHit)

{

        if(hit.gameObject.tag == ("coin1"))

        {

                 CollectedObjects += 1;

                 Coin1.active = false;

        }

        if(hit.gameObject.tag == ("coin2"))

        {

                 CollectedObjects += 1;

                 Coin2.active = false;

        }

}

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 Psychlade · Oct 21, 2011 at 08:29 AM 0
Share

Thumbs up. ;)

avatar image syclamoth · Oct 21, 2011 at 08:33 AM 0
Share

Good answer, wasted by bad formatting. Seriously, just press the 10101 button after selecting your code! I just did that, btw.

avatar image
0

Answer by Aydan · Oct 21, 2011 at 09:08 AM

 var neededCollectable : int = 5;
 var amountCollected : int = 0;
 
 function Start(){
     amountCollected = 0;
 }
 
 function Update(){
     if(amountCollected == neededCollectable){
         Application.LoadLevel(0);
     }
 }
 
 function OnTriggerEnter(collision : Collider){
     if(collision.gameObject.tag == ("Collectable")){
         amountCollected += 1;
     }
 }

This should do it just add a tag called "Collectable" to your collectables, set the collectables collider to is trigger and set the neededCollectable variable to however many collectables you need to pass the level. Hope it helps.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

"Reset Level", Application.LoadLevel 1 Answer

How to Reset Scene after Level Completion 1 Answer

reset the level? 5 Answers

How can I reset my level when the player walks on a specific floor in the game? 2 Answers

reset level on collision 3 Answers


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