Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Load a level When you hit a box

Discussion in 'Scripting' started by Sirevix, Mar 22, 2015.

  1. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    All over the internet i find this lo load a new level when hitting a box

    Code (csharp):
    1.  function OnTriggerEnter () { Application.LoadLevel ("Scene2"); }
    But where do i insert that ? in the
    Code (csharp):
    1.  // Use this for initialization
    2. void Start () {
    3.  
    4. }
    5.  
    6.  
    or

    Code (csharp):
    1.  // Update is called once per frame void Update () {
    2.  
    3. }
    i have something like this but i doesn't work

    Code (csharp):
    1.  using UnityEngine; using System.Collections;
    2.  
    3. public class NewBehaviourScript : MonoBehaviour {
    4.  
    5. // Use this for initialization
    6. void Start () {
    7.  
    8. }
    9.  
    10. // Update is called once per frame
    11. void Update () {
    12.  
    13.  
    14. function OnTriggerEnter ()
    15. {
    16. Application.LoadLevel ("Scene2");
    17. }
    18.  
    19. }
    20.  
    21. }
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,739
    You got to learn about the language your using and learn about programming in general. Your mixing C# abs unityscript in the same script and are even trying to implemenant a function in a function.

    Try to first learn the basics from the Learn section of this site, there are some tuts there that can take you from beginner with no programming knowledge to completion of a simple game.
     
  3. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    Then what do i have to do to load a new scene?
    I made my game made 1 level and everything but i don't know how to pass to the next level
    I learn with tutorials on youtube and making games
    I will never learn programing reading a book or something like that
    maybe monoDevelop hate's me xD
    (Sry for bad English)
     
  4. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    If you have got a level and "everything" you should know how and where to search to find stuff you need.

    If you don't want to read books go through the videos in the unity projects in http://unity3d.com/learn/tutorials/modules and the unity live-training section. Begin with the oldest stuff and work your way one step at the time to more complex stuff.
    From a quick look over the live training session level loading and scene switching are not in the first 40 live training videos. First you have got to familiarize yourself with the editor and coding styles of c# or unityscript.
    Maybe after the first few videos you will know what you are missing.

    btw 42 and 46 looks promising for what you need.
    And if you look at the first project video 6 you'l see how to use colliders and triggers
     
    Last edited: Mar 22, 2015
  5. petipois26

    petipois26

    Joined:
    Mar 17, 2014
    Posts:
    23
    You cannot use function in c# it is
    Void OnTriggerEnter()
     
  6. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    i tried with the live-training but i doesn't work anymore
    I downloaded the new unity and the assets they use in these videos are old that they don't work anymore and i get errors that they don't get in these videos :-|
     
  7. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    Ok so i have a new script :D

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5.  
    6. public class LevelLoad : MonoBehaviour {
    7.    
    8.     void OnTriggerEnter(){
    9.        
    10.         Application.LoadLevel ("Scene02");
    11.     }
    12. }

    And still doesn't work
    Now what is wrong again?
    Also tried
    Code (csharp):
    1.  
    2. void OnTriggerEnter(Collider other)
    3.  
    But nothing happens...
    The ball (Player has a RigidBody so the colision happens right?
    The box has the box collider and is trigger (Checked)
    And with the box selecter on the inspector
    under Script it says
    ""The associated script can not be loaded.
    Please fix any compile errors
    and assign a valid script""
     
  8. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    What assets have you used?

    The script looks fine.
    Is your class in a file named LevelLoad.cs? Filename and Classname need to have the same name to get executed.
    Does OnTriggerEnter() get executed? Easy check by using Debug.Log("On Trigger Enter of LevelLoad script executed"); inside the trigger and look at the console when you try to trigger the box.
    To see what needs to be set for colliders/triggers watch video 5 and 6 a few times. Do the whole 8 steps of Project: Roll-a-Ball in a new project file.
    That should already answer a few of your questions.
     
  9. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    OH...
    Thanx a LOT
    i saw the Roll-a-Ball Project and thought it was importing assets and stuff like they always do and never watched that videos because assets store doesn't work for me all the assets are old or i'll have to pay for them...
    i'll just delete my Whole project
    It's to messy to fix anything now xD
    and i'll start again with these videos :D
     
  10. Sirevix

    Sirevix

    Joined:
    Mar 18, 2015
    Posts:
    10
    How i can delete this forum?
    i already solved the problem
    or it's an admin thing only?