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

Change scene when enter trigger

Discussion in 'Scripting' started by Psycho5553, Jun 30, 2014.

  1. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    ok. so i got an cube that is like a trigger and when u enter that cube/trigger i want it to change to a scene called "deathscene" i need some help i cant get it to work i tried around the forums but found nothign
     
  2. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Any reason you are not using forum search or google? Copy your post title to search. If you cant figure it out after spending ten seconds, i will help you out..
     
  3. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    i searched on google but none of them worked, problaly me being retarded
     
  4. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Simple :
    Code (JavaScript):
    1. function OnTriggerEnter(other : Collider){
    2. //If a gameObject with the tag "Player" enters this trigger, load a scene.
    3. if(other.gameObject.tag == "Player"){
    4. Application.LoadLevel("Deathscene");
    5. }
    6. }
    7.  
     
  5. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    i did that but nothing happends. maybe its not the script that faks maybe its something else
     
  6. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Okay, in that case, any change you are using Character controller? (from Unity stantard assets).
     
  7. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Did you attach it to your trigger?

    Does your player have a collider attached to it and the "Player" tag?
     
  8. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    yea im using the character controller
     
  9. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Collisions acts little differently with CharacterController. More info: http://docs.unity3d.com/ScriptReference/CharacterController.html

    Test your collisions with this c# script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TriggersAndCollisions : MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.  
    9.     }
    10.  
    11.     // Update is called once per frame
    12.     void Update () {
    13.  
    14.     }
    15.  
    16.     void OnTriggerEnter(Collider other) {
    17.         Debug.Log("OnTriggerEnter");
    18.         Debug.Log(other.gameObject);
    19.     }
    20.  
    21.     void OnCollisionEnter(Collision collision) {
    22.         Debug.Log("OnCollisionEnter");
    23.         Debug.Log(collision.collider.gameObject);
    24.     }
    25.  
    26.     void OnControllerColliderHit(ControllerColliderHit hit) {
    27.         Debug.Log("OnControllerColliderHit");
    28.  
    29.     }
    30. }
    Create new scene. Add plane as ground, add character controller and two cubes so you can walk against them. Mark one of the cubes collider as trigger. You might want to select "Collapse" in Console window. If everything works like it should, OnControllerColliderHit is called all the time when charactercontoller touch the plane (ground) or any cubes. OnCollisionEnter shouldnt be called at all in this case and OnTriggerEnter should be called only when you walk through the cube with collider marked as trigger.

    edit: did you try what @Intense_Gamer94 posted? It should work if you follow the instructions in his second post..
     
    Last edited: Jun 30, 2014
  10. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    no i cant get it to work i dunno why

    some screen shots of the settings:
    http://i.gyazo.com/f4cfd012688313bf0e127e1d2e61c564.png
    http://i.gyazo.com/3970ed19e6335977c2b6874d98fddaeb.png
    http://i.gyazo.com/c2d7d1a2ac9b88a901d0c937d030e643.png

    Maybe i missed somethign
     
  11. zDemonhunter99

    zDemonhunter99

    Joined:
    Apr 23, 2014
    Posts:
    478
    This ought to work...

    Did you set your cube as a trigger? Do you tag you main player character as 'Player'? These are very important and crucial for the above code to work.

    EDIT: I just noticed that intense_gamer spelled "deathscene" as "DeathScene". Try changing this and it should work fine.

    ~Jordan
     
  12. Psycho5553

    Psycho5553

    Joined:
    Oct 2, 2013
    Posts:
    11
    i have. still dont work... i have no ide why
     
  13. Troas

    Troas

    Joined:
    Jan 26, 2013
    Posts:
    157
    Can you show a screenshot or perhaps a video of you trying to trigger it in-game and the console log as well?
     
  14. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    What does it do instead of work? Does the console window give an error like
    And my next question is whether 'deathscene' has been added to the Build Settings.[/quote][/quote]