private void OnCollisionEnter2D(Collision2D collision) { GameManager.Counter++; MyPhys.AddForce(collision.contacts[0].normal.normalized * 1000 / (Mathf.Sqrt(Physics2D.gravity.magnitude) / 2)); IClickable platform = collision.gameObject.GetComponent <IClickable>(); if (platform != null) { platform.Clicked(); } }
// Update is called once per frame void Update() { RaycastHit tHit; Ray tRay = mCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(tRay, out tHit, 100, ValidLayers)) { IClickable tInterface = (IClickable)tHit.collider.GetComponent(typeof(IClickable)); //Find Clickable object Interface if (tInterface != null) { if (Input.GetMouseButtonDown(0)) { tInterface.Clicked(tRay, tHit, true); } else if (Input.GetMouseButtonUp(0)) { tInterface.Clicked(tRay, tHit, false); } else { tInterface.Hover(tRay, tHit); } } else //Player clicked somewhere else { if (Input.GetMouseButtonDown(0)) { AgentBase[] tAgents = FindObjectsOfType <AgentBase>(); //Get all the agents in the scene foreach (AgentBase tFoundAgent in tAgents) { if (tFoundAgent.Selected) //Command selected ones { tFoundAgent.SetDestination(tHit.point); } } } } } }
private void FireRay(Click button) { // Check for error if (button == Click.None) { Debug.LogError("Fired ray without mouse press!"); } Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(r, out hit, Mathf.Infinity)) { IClickable click = hit.collider.GetComponent(typeof(IClickable)) as IClickable; if (click != null) { click.Clicked(button, hit.point); } } }