- Home /
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!
Answer by whydoidoit · Jun 16, 2012 at 09:50 AM
if(GameObject.Find("Pick up")) {
Application.LoadLevel(1);
}
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);
Good point. Why can't it be found - because it has been destroyed. Does this test need to happen in Update at all?
If the script that triggers the spawn and/or destruction also triggers the level change, no.
Thanks. How can I test if the object "pickup" does NOT exist?
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!
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"))
...
! is a boolean operator, rigth? maybe can you explain something about, also for me thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613072843im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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