I am using OnMouseDown() like following
public class Rotateprents : MonoBehaviour
{
GameObject P1;
GameObject C1;
GameObject C2;
void OnMouseDown()
{
if (transform.name.Contains("Parent"))
{
P1 = transform.gameObject;
C1 = P1.transform.GetChild(0).gameObject;
C2 = P1.transform.GetChild(P1.transform.childCount - 1).gameObject;
Debug.Log(C1);
}
else if (transform.name.Contains("child"))
{
P1 = transform.parent.gameObject;
C1 = P1.transform.GetChild(0).gameObject;
C2 = P1.transform.GetChild(P1.transform.childCount - 1).gameObject;
}
}
public void rotateobj()
{
Debug.Log(C1);
}
}
Gameobject C1 is empty in rotateobj(). Why?