Search Unity

How to save data with a collision?

Discussion in 'Scripting' started by Hectorastacio1, Nov 16, 2017.

  1. Hectorastacio1

    Hectorastacio1

    Joined:
    Sep 11, 2017
    Posts:
    60
    I want to know what I need to add to my script so when a collision happens with an object named cylinder happens then data in this case the name of the object (test1, TEST2,etc.) is saved.

    I currently have
    void OnCollisionEnter(Collision collision)
    {
    Debug.Log("I hit : " + collision.gameObject.name);
    int rand = Random.Range(0, 10);

    if (rand == 0)
    {
    SpawnObject(test1);
    }
    else if (rand == 1)
    {
    SpawnObject(TEST2);
    }
    else if (rand ==2)
    {
    SpawnObject(TEST3);
    }
    else if (rand == 3)
    {
    SpawnObject(TEST4);
    }
    else if (rand == 4)
    {
    SpawnObject(TEST5);
    }
    else if (rand == 5)
    {
    SpawnObject(TEST6);
    }
    else if (rand == 6)
    {
    SpawnObject(TEST7);
    }
    else if (rand == 7)
    {
    SpawnObject(TEST8);
    }
    else if (rand == 8)
    {
    SpawnObject(TEST9);
    }
    else if (rand == 9)
    {
    SpawnObject(TEST10);
    }

    }
    void OnCollisionStay(Collision collision)
    {
    }
    void OnCollisionExit(Collision collision)
    {
    }
    }
     
  2. Hectorastacio1

    Hectorastacio1

    Joined:
    Sep 11, 2017
    Posts:
    60
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Please use script tags. Also don't bump after 7 minutes.
     
  4. Hectorastacio1

    Hectorastacio1

    Joined:
    Sep 11, 2017
    Posts:
    60
    Thanks for the help