Im instantiating from a prefab a series of objects (with canvas renderer, they’re ui objects) that have the following script inside. I want a click to trigger only for the particular object i’m clicking on. Instead right now it triggers for all of them. It shows the specific variables of each individual item, but its triggering for all three at the same time. I’m stuck and don’t know what else to tweak thanks for your help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class OnClick : MonoBehaviour {
// Use this for initialization
void Start () {
}
void OnMouseOver(){
if(Input.GetMouseButtonDown(0)){
Debug.Log("clicked");
/*
GameObject clickedItem;
clickedItem = gameObject;
if (clickedItem == null) {
Debug.Log ("clickedItem is null");
} else if (clickedItem != null) {
Debug.Log ("clickedItem is not null");
}
GameObject title = clickedItem.transform.GetChild (0).gameObject;
if (title == null) {
Debug.Log ("title is null");
} else if (title != null) {
Debug.Log ("title is not null");
}
//Destroy (title);
Transform transform = title.transform;
Text text1 = transform.GetComponent<Text>();
if (text1 == null) {
Debug.Log ("text1 is null");
} else if (text1 != null) {
Debug.Log ("text1 is not null");
}
Debug.Log ("item text is: " + text1.text);
*/
}
}
// Update is called once per frame
void Update () {
OnMouseOver ();
}
}