Hi there!
I have a problem with actions with clicked gameObject.
I have 10x10 board full off random colour rectangles, which are actually prefabs.
After generating this board (called map in my code) I would like to destroy selected rectangles by clicking them.
Map is a parent, and every prefab rectangle is a child of it. Map has script On_clicked, which should get reference to clicked gameObject and destroy it. Every rectangle has script as well, which should send reference to it.
After clicking on rectangle, nothing happens.
Maybe You will know where the problem is…
So here is the code for single rectangle:
public class czerwony : MonoBehaviour {
public On_Click control;
void Start()
{
control = GameObject.Find("map").GetComponent<On_Click>();
//control = GetComponent<On_Click>();
}// end start
void OnMouseDown()
{
control.DoSomethingToClicked(this.transform.gameObject);
//Destroy(gameObject);
}
// Update is called once per frame
void Update () {
}
And here is for map:
public class On_Click : MonoBehaviour {
//GameObject puzzle;
// Use this for initialization
public GameObject clickedGameObject;
public void DoSomethingToClicked(GameObject clickedOn)
{
clickedGameObject = clickedOn;
Destroy(clickedGameObject);
}
void Start () {
}
// Update is called once per frame
void Update ()
{
}
}