Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How to I add a collision's GameObject to an array?

$
0
0
The code with all the other bits taken out: --- var lGround:Array; function Start () { var lGround= new Array(); } function OnCollisionEnter(other:Collision){ if(other.gameObject.tag == "Ground"){ var gcontainer:GameObject=other.collider.gameObject; print(gcontainer); lGround.Add(gcontainer); } } The print line returns (5x): Cube (UnityEngine.GameObject) UnityEngine.MonoBehaviour:print(Object) Which seems to be the cube object. (There are five of them that it is falling into.) I then get this error (5x): NullReferenceException: Object reference not set to an instance of an object Lemming.OnCollisionEnter (UnityEngine.Collision other) (at Assets/Scripts/Lemming.js:46) How do I add the object colliding to an array properly?

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>