//Relaese Handling private void ScreenClickEndedHandle() { if (lastClickedBtn == null) { return; } EngButton btnComp = lastClickedBtn.GetComponent <EngButton> (); if (btnComp == null) { return; } btnComp.isBegan = false; if (btnComp.resetIconOnRelease) { if (btnComp.normalIcon != null) { btnComp.spriteRendererComp.sprite = btnComp.normalIcon; } } if (!string.IsNullOrEmpty(btnComp.message)) { eventOb.SendMessage(btnComp.message, btnComp.messageObject); //call the given method which is inside Events.Cs } else { Debug.LogWarning("empty message on <i>" + lastClickedBtn.name + "</i>click"); //you missed to add event name } lastClickedBtn = null; }
//General Handling private void ScreenClickHandle(GameObject ob, bool isTouchBegain) { string objname = ""; // name of button that ray hit it if (ob != null) { objname = ob.name; } foreach (GameObject btn in buttons) { if (btn == null) { continue; } EngButton btnComp = btn.GetComponent <EngButton> (); if (btnComp == null) { continue; } if (objname == btn.name) { if (!btnComp.isBegan) { btnComp.isBegan = true; lastClickedBtn = btn; if (btnComp.hoverIcon != null) { btnComp.spriteRendererComp.sprite = btnComp.hoverIcon; } if (btnComp.clickReleaseSFx != null) { AudioSource.PlayClipAtPoint(btnComp.clickReleaseSFx, Vector3.zero); } } } else { if (!isTouchBegain && btnComp.isBegan) { lastClickedBtn = null; btnComp.isBegan = false; if (btnComp.normalIcon != null) { btnComp.spriteRendererComp.sprite = btnComp.normalIcon; } } } } }