Index of some array object

Hi guys!
 
i just learn qici for 2-3 weeks.
how can i get index of array object that i clicked?
for example, i have 3 array image object and i wanna know the index of image that i clicked.
Untitled.png
Has invited:

george828

Favor from:

Hello! first of all you must make the element interactive, There is a ckechbox on the right side panel, Section called Hit area.
 
After you need to add script to the parent element UIRoot element or every single one what you want to be clickable.
 
My choice would be to add script to UIRoot element and manipulate all elements from there.
 
if you will add script to UIRoot you need to add event listener on each image nodes
 
will be good if you will make another empty node inside of UIRoot, Lets say 'flagsContainer' and place all your image (flags) nodes there. after in awake function write code:
 
var _self = this;
var root = _self.gameObject;
var flagsContainer = root.find('flagsContainer');
after add listeners to all image nodes inside 'flagsContainer'
 
for(var i = 0; i < flagsContainer.children.length; i++){
_self.addListener(flagsContainer.children[i].onClick, _self.flagClick, flagsContainer.children[i]);
}
after make another protorype function
main.prototype.flagClick = function(element) {
console.log(element);
};
and there in console you can see the object of clicked element.
 

 
 
 

To reply to a question, please Login or registered