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

Assigning a gameobject to another

Discussion in 'Scripting' started by Soumikbhat, Jul 11, 2014.

  1. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    Is there a way to assign a gameobject to another?

    Like:

    Code (CSharp):
    1. public GameObject empty;
    2. void OnCollisionEnter(Collision collision)
    3. {
    4. if(collision.gameObject satisfies a certain criteria)
    5. {
    6. empty=collision; //error line
    7. }
    8.  
    9.  
    10. }
    I want to work with the collided object in my update function. But since OnCollisionEnter() is only called when there's a collision, I need to 'store' my collision gameobject in another public gameobject so that I can use it in my other functions like Update etc.
     
  2. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    Magiichan likes this.
  4. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403