Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

Variables return 0 even after assigning values.

$
0
0
Hello all, I'm trying to get variables *xID* & *yID* of *Sensor* script on *Sensor* gameobject through another *Cube* script on *Cube* gameobject. Although *Sensor* script was able to convert the values and assign into *xID* & *yID* on trigger, but the xID & yID returns as 0 when called from *Cube* script. I must have missed something. All help much appreciated. Cheerz! ## Cube.cs ## public int cubeXID, cubeYID; public Sensor sensor; void OnMouseDown(){ sensor = GetComponentInChildren< Sensor >(); if( sensor != null ){ cubeXID = sensor.XID; cubeYID = sensor.YID; } else { Debug.Log ("missing sensor"); } } ## Sensor.cs ## public int xID, yID; void OnTriggerEnter( Collider other ){ if ( other.tag == "Ball" ){ xID = (int) ( other.transform.position.x ); yID = (int) ( other.transform.position.y ); } } public int XID { get {return xID;}} public int YID { get {return yID;}}

Viewing all articles
Browse latest Browse all 215

Trending Articles



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