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 varie-tea · Jun 16, 2012 at 09:36 AM · gameobjectmac

Basic scripting problem

Hello,

I'm new to Unity (version 3.5.2 for Mac) and have a problem with this script:

 function Update () {
     if GameObject : Pick up = 0{
         Application.LoadLevel(1):
     }
 }

It's supposed to check if the GameObject "Pick up" exists. If yes, it should go into the scene 1 – if no, it should do nothing!

Please HELP! Many 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

2 Replies

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

Answer by whydoidoit · Jun 16, 2012 at 09:50 AM

   if(GameObject.Find("Pick up")) {
           Application.LoadLevel(1);
     }
Comment
Add comment · Show 14 · 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 Wolfram · Jun 16, 2012 at 01:15 PM 1
Share

Note you shouldn't use Find() in Update(), since it is extremely slow, especially once your scene gets more complex.

Ins$$anonymous$$d, it might be better to have the script that spawns "Pick up" take care of loading the new level, or trigger a function in your game manager which then calls Application.LoadLevel(1);

avatar image whydoidoit · Jun 16, 2012 at 01:20 PM 0
Share

Good point. Why can't it be found - because it has been destroyed. Does this test need to happen in Update at all?

avatar image Wolfram · Jun 16, 2012 at 02:27 PM 0
Share

If the script that triggers the spawn and/or destruction also triggers the level change, no.

avatar image varie-tea · Jun 17, 2012 at 09:14 AM 0
Share

Thanks. How can I test if the object "pickup" does NOT exist?

avatar image whydoidoit · Jun 17, 2012 at 09:15 PM 0
Share

Put an ! infront of your test.

 if(!GameObject.Find...
Show more comments
avatar image
0

Answer by varie-tea · Jun 16, 2012 at 12:07 PM

It seems my description of the problem wasn't clear.

This script makes it load the scene 1 if the object "pickup" exists, but it should load the scene if it does NOT exist!

Thanks again!

Comment
Add comment · Show 3 · 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 whydoidoit · Jun 16, 2012 at 12:08 PM 0
Share

Please use comments not answers when commenting. There is an add new comment link on the right of the screen.

  if(!GameObject.Find("Pick up"))
    ...
avatar image Ingen · Jul 13, 2012 at 01:08 PM 0
Share

! is a boolean operator, rigth? maybe can you explain something about, also for me thanks

avatar image whydoidoit · Jul 13, 2012 at 03:03 PM 0
Share

It means "Not"

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

Activate/Deactivate Script from another Object. 3 Answers

how to build & populate an array available to all scripts on all objects? 1 Answer

How do I change the text of a GUIText object through another GameObject using a variable? 2 Answers

Rename gameobject (game not running, via inspector script) 2 Answers

Load a scene/level when enemy is close... 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