• 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 john 2 · Aug 12, 2010 at 08:52 PM · cameramainmenu

Keyword that means "nothing"?

In my game I want it that when I advance to the next level, my camera comes with me(is not destroyed), but when I die in my game I want that when I go back to the main menu my camera is destroyed. I am wondering if there is a word or phrase that means "nothing".

My script:

if(Application.LoadLevel ("mainmenu"))
{
    //what would i put here?    
}
else
{
    function Awake () 
    {
        DontDestroyOnLoad (this);
    }   
}

this script is attached to my level 1 main camera. if there is no word/or phrase i can put in to replace the //what would I put here? comment, then what can i do?

Comment
Add comment · Show 3
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 Cyclops · Aug 12, 2010 at 09:12 PM 0
Share

@john, I reformatted the code and removed the semi-colon at the end of the first line. Note if you have that in your code, it needs to be removed also. Second, although I didn't fix it - the Awake function can not go in the else.

avatar image john 2 · Aug 12, 2010 at 09:19 PM 0
Share

@Cyclops, i am just learning this and i am trying to is when i die go to the main menu without the camera, but when i advance to the next level for the camera to come with me. also i an error. it says "expecting EOF(does that mean end of function?),found 'else' does this have anything thing to do with the empty brackets? Please comment or answer back. Thanks!

avatar image Wolfram · Aug 12, 2010 at 09:24 PM 1
Share

It means "end of file". Any code like that must be located somewhere within a function.

1 Reply

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

Answer by Wolfram · Aug 12, 2010 at 09:22 PM

To answer your question literally, the ";" is the empty statement, so in theory you could put that in there. But instead of this:

if(condition)
{
    ;
}
else
{
    // do something
}

you can simply reverse the condition:

if(!condition)
{
    // do something
}

However, what you actually want to do doesn't work the way you describe. For starters, "function Awake()" cannot be within the if/else. Keeping objects between levels alive while making sure there is only one copy when returning to the level that created your object is tricky and laden with pitfalls, especially since Unity doesn't behave correctly or consistently in this regard.

But what you describe, creating your camera in "level 1", and keeping it alive until you return to "mainmenu", should be possible by attaching something like this to your Camer a in level 1:

function Awake(){ DontDestroyOnLoad(); }

function OnEnable(){ if(Application.loadedLevelName=="mainmenu") Destroy(gameObject); }

However, when doing this you also have to take care that there are no other "Main Cameras" in your other levels, so either remove them (which makes testing these levels difficult), disable them by hand before you make a build (which is tedious), or by script (which is complicated and prone to the same pitfalls as above).

EDIT: Why do you need to keep the camera between levels? if all you want to keep is the orientation and position of the camera, it is much better to create a script that does just that, instead of trying to keep the whole Camera persistent between levels.

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 john 2 · Aug 12, 2010 at 09:34 PM 0
Share

Thank you so much! It worked Perfectly!! i am a pre-teen just learning the concepts of the C++, C#, and JavaScript scripting. Your help is GREATLY appreciated!! Thanks!!!!!!!!!!!!!!!!!!!!!

avatar image burnumd · Jun 10, 2011 at 07:35 PM 1
Share

You can also just have empty blocks between curly braces, ie "if (condition) { }" You're right, the OP would be better off reversing the condition, but if you want to have an empty block, just leaving it empty works about every where (class definitions, void functions, loops, and conditional blocks).

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

An object reference is required to access a non static member. 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Backgrounds moving at different speeds? 1 Answer

Problems implementing a 3rd person static camera 0 Answers

Loading pictures, how to hide and load in-game pictures? (details) 0 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