Search Unity

collison check

Discussion in 'Scripting' started by Nightshade1, Feb 25, 2012.

  1. Nightshade1

    Nightshade1

    Joined:
    Feb 6, 2011
    Posts:
    95
    how do i make it so when a ball hits a specific cube it loads the next level and the ball has no tag how would this be done?
     
  2. Terminator

    Terminator

    Joined:
    Feb 21, 2010
    Posts:
    17
    Well first is the cube that you're running into a trigger or not?

    If it's not a trigger you can just use:

    Code (csharp):
    1. function OnCollisionEnter(collision:Collision){
    2.     //checking the name of the collided object
    3.     if (collision.transform.name=="NameofObjectCollidingWith")
    4.     {
    5.         //loading the new level
    6.         Application.LoadLevel("NameofLevel");
    7.     }
    8. }
    What's happening is that when the cube collides with another collider this function is called once. Then it's checking the name of the collided object with the code "collision.transform.name". And then you would load the new level with "Application.LoadLevel(()".

    Attach the above script to your cube object that your ball is going to run into (it's in unity javascript). Make sure to replace the names with the name of your ball object and the name of the new level to be loaded.

    You also need to attach a rigidbody to the cube, so the function will trigger. I'd recommend setting the rigidbody to kinematic unless you want it to be affected by physics.