Search Unity

Collision.gameObject - How to make the gameobject a gameobject in your scene?

Discussion in 'Scripting' started by luhjgh, Sep 30, 2011.

  1. luhjgh

    luhjgh

    Joined:
    Jan 1, 2011
    Posts:
    128
    I have this house in my scene. I want the house you bump into to teleport you to another scene. I tried this code:
    Code (csharp):
    1.  
    2. var gameObject : Transform;
    3. function Update () {
    4. if (Collision.gameObject)
    5. Application.LoadLevel("Jungle planet");
    6.  
    7. }
    8.  
    but it doesn't work. How can I make the house you hit teleport you to the jungle planet?
     
  2. flaminghairball

    flaminghairball

    Joined:
    Jun 12, 2008
    Posts:
    866
    Take a look at OnCollisionEnter.
     
  3. majmun

    majmun

    Joined:
    Feb 2, 2011
    Posts:
    140
    Something I've been doing with collisions but in C#

    Code (csharp):
    1.  
    2.     void OnTriggerEnter (Collider other)
    3.     {
    4.         if (other.tag == "Ground")
    5.         {
    6.             Onground = true;
    7.         }
    8.         if (other.tag == "Trampolin")
    9.         {
    10.             c = 100;
    11.         }
    12.     }
    13.     void OnTriggerExit (Collider other)
    14.     {
    15.         if (other.tag == "Ground")
    16.         {
    17.             Onground = false;
    18.         }
    19.     }
    20.  

    so you would need something like:

    Code (csharp):
    1.     void OnTriggerEnter (Collider other)
    2.     {
    3.         if (other.tag == "House")
    4.         {
    5.             Application.LoadLevel......
    6.         }
    7.     }
    8.  
    add tag check just so you don't hit anything and that triggers another scene

    this would be in C# I hope it helps,
    I have looked in UNITY HELP FILE and for java it says this:

    Code (csharp):
    1.  
    2. // Destroy everything that enters the trigger
    3.  
    4. function OnTriggerEnter (other : Collider) {
    5. Destroy(other.gameObject);
    6. }
    7.  
     
  4. luhjgh

    luhjgh

    Joined:
    Jan 1, 2011
    Posts:
    128
    Thank you I got it working now :D