private void Click() { clickTime = 0f; isClicked = false; Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit); if(selected != null) { if(hit.transform != selected.transform) { Debug.Log("A "+selected.transform+" was selected, but "+hit.transform+" was clicked"); //selected.GetComponent<OnClickScript>().OffClick(); click.OffClick (); selected = null; } } if(hit.transform != null){ click = hit.transform.GetComponent<OnClickScript>(); } if(click != null) { Debug.Log(hit.transform+" was clicked"); click.OnClick(); selected = hit.transform.gameObject; } }
void Start() { OnClickScript tmpScript = gameObject.GetComponent <OnClickScript>(); tmpScript.clickFunctionList.Add(OnClick); tmpScript.hoverFunctionList.Add(OnHover); myAnimator = gameObject.GetComponent <Animator>(); }
void Start() { OnClickScript tmpClickScipt = gameObject.GetComponent <OnClickScript>(); tmpClickScipt.clickFunctionList.Add(OnClick); tmpClickScipt.hoverFunctionList.Add(OnHover); myAnimator = gameObject.GetComponent <Animator>(); myAnimator.SetFloat("RandSpeed", UnityEngine.Random.Range(0.9f, 1.1f)); }
// Start is called before the first frame update void Start() { OnClickScript mouseScript = gameObject.GetComponent <OnClickScript>(); mouseScript.hoverFunctionList.Add(OnHover); mouseScript.clickFunctionList.Add(OnClick); iconObject = transform.GetChild(0).gameObject; iconAnimator = iconObject.GetComponent <Animator>(); mySprite = iconObject.GetComponent <SpriteRenderer>(); // mySprite.sprite = myIcon; iconAnimator.SetFloat("RandomTime", Random.Range(0.8f, 1.2f)); questionManager = GameObject.Find("QuestionHolder").GetComponent <MapQuestionManager>(); }
// Update is called once per frame void Update() { Ray clickRay = myCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Does the ray intersect any objects excluding the player layer if (Physics.Raycast(clickRay, out hit)) { Debug.DrawRay(transform.position, (hit.point - transform.position) * hit.distance, Color.yellow); OnClickScript clickScript = hit.collider.gameObject.GetComponent <OnClickScript>(); if (clickScript) { if (Input.GetMouseButtonUp(0)) { clickScript.Clicked(); } clickScript.OnHover(); } } }