Search Unity

Collision information collected by collision events is too private.

Discussion in 'Scripting' started by Tenhitcombo, Feb 14, 2020.

  1. Tenhitcombo

    Tenhitcombo

    Joined:
    Jan 13, 2018
    Posts:
    1
    I was just wondering if it's possible to send the data gathered by the collision event to a public member variable. This seems like it would make for some pretty interesting solutions if done right. Has anyone ever attempted this? If so what were the results?

    Code (CSharp):
    1. public void OnCollisionEnter (Collision coll) {
    2.     // make coll data publically acessible  OR
    3.     // make coll data a singleton?
    4.     collData = coll.gameObject;
    5.    
    6.    // Not sure how to implement this...
    7. }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Yeah can have a public variable of type Collision and just assign it, and any other object could access that data. What in particular are you trying to use the data for?
     
  3. mustafatat

    mustafatat

    Joined:
    Oct 1, 2017
    Posts:
    6
    If I understand it correctly. You are talking about using the "OnCollisionEnter" function publicly. I think instead you can make the CollData variable public and access it from anywhere. Or you can send CollData to another script.