hi everybody, i am trying to figure out one thing, that seemed easy at first, though i am just a beginner.
i want to have only one script in the parent gameobject, and i will have four child
and i want to detect when user clicked any of the children...is this possible without having
scripts for every child?
Child class (let's say it's called `ChildClass`, but you can name it whatever as long as it's updated in the parent class script):
public delegate void OnTouchedDelegate( GameObject touchedObject );
OnTouchedDelegate touchDelegate;
public OnTouchDelegate TouchDelegate
{
set { touchDelegate = value; }
}
void OnMouseDown() // monobehaviour method
{
touchDelegate( gameObject );
}
You might want to put some error handling in there, like maybe check to see if the touch delegate is not null if that's a case you want to handle, or if the child object has a collider before adding the script, or whatever your specific needs are.