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 adam199 · Nov 20, 2015 at 07:17 AM · c#scene-loadingscorelevels

How do I make my game change levels after collecting all objects?

I am very new to unity and I am having trouble with getting my game to change levels after I have collected all objects. I currently have a working main menu with buttons that allow me to exit and my first scene with an object collect system that displays score in the top right of my screen. // JavaScript var score = 0; function OnTriggerEnter( other : Collider ) { Debug.Log("OnTriggerEnter() was called"); if (other.tag == "coin") { Debug.Log("Other object is a coin"); score += 1; Debug.Log("Score is now " + score); Destroy(other.gameObject); } } function OnGUI() { GUILayout.Label( "Score = " + score ); }

This code works perfectly for collecting the objects and counting score and this is what I am using to keep count.

I am wondering if anybody can help me work out a way so that when my score reaches a certain point, e.g... 3 points, my game will progress to the next level where I could create a more challenging terrain and harder to find collectables.

Any feedback is appreciated. 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kimi073 · Nov 20, 2015 at 07:54 AM

Hi,

I have two ways you may consider.

One is using Lerp which help you to change between multiple game object position and this is the way I use in most of my 2D games to change my screen (for example: from main menu to exit menu,..). For your case, this could be used to change between two objects which hold two different levels. However this needs a bit of practise to get over it well. But if you could, this would definitely your best tool.

[Link for Lerp documentation]: http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

The second way, which I may recommend for beginner like you because it's what I think the easiest way is using "LoadLevel" which load another scene and in this case, load another level. I don't know how it's exactly written in JS (because I don't use it) but what here in CS:

//Your above code

//Put these lines of code in Update function

//You have to make a scene called "level2" or whatever you may want and put exactly in the quotation mark

 if (score >= 3) {
     Application.LoadLevel("level2");}

Sorry for my bad English. Feel free to ask further if you don't understand at any part. This is the first time I answer someone so may get the answer confusing

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 KdRWaylander · Nov 20, 2015 at 08:44 AM 0
Share

I'm not sure to undersand your first way, what are you lerping from and to ? If it's just about moving from a position to an other, you'd rather be using Vector3.$$anonymous$$oveTowards(); Using Lerp to move objects is a bad habit and a twisted way of using it ^^

But anyway, i do agree with your second way ! You can use the score variable or a objectCount at which every picked object would add 1 (in case that score and picking objects is not fully related)

avatar image Kimi073 KdRWaylander · Nov 20, 2015 at 09:22 AM 0
Share

In the first way, I add the main camera in a game object as a child and other screen in different game objects. Then I use Lerp to move the game object which contain the main camera to the game object which holds the right screen that I want.

LoadLevel() is the first method I learn and super easy and I really encourage using it ins$$anonymous$$d of Lerp if you don't want to learn too much at once.

@$$anonymous$$dRWaylander Ya thanks so much for your advise. I was trying to use $$anonymous$$oveToward() too but find Lerp kinda "fancier" to use because I can also make screen changing effect later on when I move to 3D. Anyways thanks so much :3

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to disable dontdestroyonload on a specific scene 2 Answers

Best server-side score storage service 0 Answers

How do switch scene with singleton pattern unity3d C# 2 Answers

Switching between scenes saving and translate to previous position 0 Answers

Scoring system not working. 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