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. Dismiss Notice

My Code To Move to Another Level is not working.

Discussion in 'Editor & General Support' started by greatUnityGamer, Mar 12, 2015.

  1. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    #pragmastrict

    functionOnTriggerEnter (Col : Collider ) {
    if( Col.tag == "Player" ){
    Application.LoadLevel( "Level2" );
    }
    }

    That's the Script.
    And just to let you know I DO have both levels loaded in the Build settings.
    And yes the Box i use as a Trigger has the IS TRIGGER checkbox checked. Then I did drag the script into the Box. And then Yes the First Person Controller( Which has Graphics and Main Camera inside it when you expand it in the hierarchy) has TAG set to Player.

    But for some reason when i play test the game and pass through the box, nothing happens.
    Why is this?
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Write a Debug.Log("") in your OnTriggerEnter function and one into your if statement and see what is getting printed.
     
  3. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Does your first person controller have a rigidbody? It should.
     
  4. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    No i don't think so. I am just using the First person controller that came with a package I bought like "Rainscape" and "DayNight Cycle". In other words, i'm starting my own scenes OFF of those package's Demo scenes.

    When i look inside their inspector in the First person controller inspector, it doesn't say nothing about Rigid bodies. So i think they don't have rigid bodies. DO i need to add one?

    And if so, i just add a Rigid body component, and that's all i have to do? or do i have to set some specific settings?
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Add a rigidbody and set "is kinematic", so it won't interfere with your controller.
    You need a rigidbody if you want to trigger something, either on your player or on your trigger.
     
  6. greatUnityGamer

    greatUnityGamer

    Joined:
    Aug 11, 2013
    Posts:
    182
    Thanks so much i'll do that.