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;}}