Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

load level on touch

Discussion in 'Scripting' started by blutackboy, Nov 25, 2014.

  1. blutackboy

    blutackboy

    Joined:
    Nov 19, 2014
    Posts:
    4
    I have made my game and menu but now I just need a script so when the enemy gets in a certain range or "touches" my character, it will load my menu scene (Im a little stumped with this code but i know it has to "loadlevel(0)" on the touch).

    Cheers :D (ill let you know if someones has answered my question :D)
     
  2. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
  3. blutackboy

    blutackboy

    Joined:
    Nov 19, 2014
    Posts:
    4
    well now i have this new code:
    1. function OnCollisionEnter (collision : collision) {
    2. if (collision.gameobject .name=="GOBLIN"")
    3. Application.loadlevel (Application.loadlevel0);
    4. }

      my goblin has the tag "GOBLIN", i have another scene and in the build settings it is indeed numbered 0 and my fps character has a rigid body but i don't seem to know whats wrong, any ideas guys? In the picture is the code that I slightly edited :) loadlevelcode.PNG
     
  4. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    Please keep in mind that there is a difference between the GameObject's tag and name; so keep that in mind with the check inside of your method.