private void swipe (string currentLocation, Vector2 mStartPosition){ GameObject objectHit = MyHelpers.getRaycastedGameObject(new Vector3(mStartPosition.x,mStartPosition.y,1f),Camera.current); if (objectHit != null ) { MyHandClass hand = objectHit.GetComponent<MyHandClass>(); if (hand != null && hand.location.Equals (currentLocation)) { hand.OnSwipe (); } } }
void Update() { #if UNITY_EDITOR if (Input.GetMouseButtonDown(0)) { GameObject objectHit = MyHelpers.getRaycastedGameObject(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1f), cam); if (objectHit != null) { MyHandClass hand = objectHit.GetComponent <MyHandClass>(); if (hand != null) { hand.OnSwipe(); } } } #endif }
public static GameObject getRaycastedGameObject(Vector3 origin, Camera cam) { Ray ray; RaycastHit hit; var mousWorldPos = cam.ScreenToWorldPoint(origin); var direction = cam.ScreenPointToRay(origin).direction; ray = new Ray(mousWorldPos, direction); UnityEngine.Debug.DrawRay(ray.origin, 1000f * ray.direction, Color.green, 1.1f, true); //agregado ledr --- GovernmentWorkOut int mask = (1 << LayerMask.NameToLayer("Scroll0")); if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask)) { GameObject mgame = hit.transform.gameObject; if (mgame.name == "circle(Clone)") { return(mgame); } } //----------- if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { GameObject mgame = hit.transform.gameObject; if (mgame != null) { MyHandClass hitGo = mgame.GetComponent <MyHandClass>(); SpriteRenderer hitGo3 = mgame.GetComponent <SpriteRenderer>(); if (hitGo != null || (hitGo3 != null && (hitGo3.gameObject.name.ToUpper().Contains("OBS") || hitGo3.gameObject.name.Contains("FinalPoint") || hitGo3.gameObject.name.Contains("StartPoint")))) { return(mgame); } } } return(null); }