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 omegapilot360 · Apr 26, 2015 at 09:52 PM · scriptingproblem

Script Structure Problem

I found a script that goes like this;

 //Script to revert winning player back to main menu
 
 var levelToLoad : String;
 
 function OnTriggerEnter(hit : Collider) { Application.LoadLevel(levelToLoad);
 
 }//END FUNCTION ONTRIGGERENTER 

But when I copied and pasted into new script, it tells me to fix compiler errors. How should I structure this script? Please help I am new to coding.

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 JNaski · Apr 26, 2015 at 10:11 PM 0
Share

What does the error tell you? I would assume that if you just use it like that so it would say something about the "levelToLoad" because it is not defined on that piece of code.

avatar image omegapilot360 · Apr 26, 2015 at 11:02 PM 0
Share

it doesn't say what the error is, it just tells me to fix it.

avatar image JNaski · Apr 26, 2015 at 11:54 PM 0
Share

the console usually always says what error and what line

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Calum1015 · Apr 27, 2015 at 01:43 AM

 var levelToLoad : String;
 
 function OnTriggerEnter(hit : Collider)
 {
 Application.LoadLevel(levelToLoad);
 }

I believe that is what you need.

Comment
Add comment · Show 4 · 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 JNaski · Apr 27, 2015 at 12:25 PM 0
Share

Usually the errors are not caused by the layout of the code..or am I just missing the modifications in syntax. Without testing the code I would say that just by dropping the Application.LoadLevel down a line won't solve the problem. I would assume that the problem is that the code tries to load a level defined bu levelToLoad but it's not defined...you need to load a scene. For example I used Application.LoadLevel ("$$anonymous$$urhapeli"); in my project. The "$$anonymous$$urhapeli" is the name of the scene that I want to load. That little piece of code tries to load a scene that is defined by the var levelToLoad but in that little piece it is not defined with the scene name...So without knowing anything else about the code I would say that it is the problem

avatar image Calum1015 · Apr 27, 2015 at 01:42 PM 0
Share

I tested this code on an object and it works fine.

avatar image Calum1015 · Apr 27, 2015 at 01:43 PM 0
Share

Oh and also, you define levelToLoad in the inspector. As long as you add the scene to the build settings it should work.

avatar image JNaski · Apr 27, 2015 at 02:54 PM 0
Share

But still I don't think the commands need to be on new lines :D 'cos I usually have this one liner when I load from main menu

public void StartButton(){Application.LoadLevel ("Playground");}

Just need to change the name and it needs to be included to build settings. or does JS require them to be on new lines?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Character and enemy don't damage each other 1 Answer

My camera is not working, nor are my bullets? 0 Answers

Assets/Scripts/Racing System/RacerPositionObject.cs(27,1): error CS0029: Cannot implicitly convert type `float' to `bool' 1 Answer

How to create a PNG / AI only with a script ??????? 1 Answer

Every script says "can not load script" and that there is no monobehavior in the file 2 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