private void MouseButtonDown() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); int count = Input.touchCount; if (count == 1) { Touch touch = Input.GetTouch(0); ray = cam.ScreenPointToRay(new Vector3(touch.position.x, touch.position.y)); } GameObject invObj = null; if (_inventory.Showing()) { invObj = _inventory.OverObject(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)); _inventory.SetSelected(invObj); } RaycastHit hit; if (Physics.Raycast(ray, out hit) && invObj == null) { if (hit.collider.gameObject == gameObject) { _inventory.Toggle(); } else if (hit.collider.gameObject.GetComponent <interactuable>()) { //TODO:Desactivar script camera // targetLocation = thisTransform.position; cam.GetComponent <customLookAt>().enabled = false; _interactuable = hit.collider.gameObject.GetComponent <interactuable>(); Vector3 screenPos = cam.WorldToScreenPoint(hit.collider.gameObject.transform.position); _interactuable.ShowMenu(screenPos); _raster.particleSystem.Stop(); cRaster = (GameObject)GameObject.Instantiate(_raster, hit.collider.gameObject.transform.position, new Quaternion(0, 0, 0, 0)); cRaster.SetActive(true); _inventory.Hide(); } else { if (invObj == null) { _inventory.Hide(); } float touchDist = (transform.position - hit.point).magnitude; if (touchDist > minimumDistanceToMove) { targetLocation = hit.point; } Quaternion quat = Quaternion.AngleAxis(270, new Vector3(1, 0, 0)); GameObject.Instantiate(onClickCursor, targetLocation, quat); } } }
private void MouseButtonUp() { //Fem release tenint un objecte del inventari seleccionat if (_inventory.Showing()) { GameObject invObj = _inventory.GetSelected(); Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0); GameObject otherObj = _inventory.OverObject(mousePos); if (invObj != otherObj) { if (otherObj != null) //Estem intentant combinar objectes que son dins l'inventari { } else //Estem intentant combinar amb un objecte de l'escena { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent <interactuable>()) { //Cridar a la funcio d combinar objectes //Debug.Log ("Desti de combinacio: " + hit.collider.gameObject); interactuable interDesti = hit.collider.gameObject.GetComponent <interactuable>(); bool isGood = interDesti.comprobarInteraccio(invObj); if (isGood) { //Debug.Log("Combinacio Correcta!"); Application.LoadLevel("end"); } } } } } if (invObj) { invObj.transform.position = new Vector3(1, 1, 0); invObj.guiTexture.pixelInset = new Rect(0, 18 - 100, 64, 64); invObj.guiTexture.color = new Color(0.5f, 0.5f, 0.5f, 0.5f); _inventory.Hide(); _inventory.SetSelected(null); } } //Fem release tenint un menu contextual desplegat if (_interactuable != null) { Vector3 cPos = Input.mousePosition - _interactuable.GetScreenPosition(); for (int i = 0; i < _interactuable.Actions.Length; i++) { //Comprovar distancia del puntero al las opciones Vector3 aPos = new Vector3(_interactuable.Actions[i].guiTexture.pixelInset.x + 32, _interactuable.Actions[i].guiTexture.pixelInset.y + 32, 0); float aDist = Vector3.Distance(aPos, cPos); if (aDist < 32) { _interactuable.Actions[i].GetComponent <Action>().Do(); } } GameObject.DestroyObject(cRaster); _interactuable.HideMenu(); _interactuable = null; cam.GetComponent <customLookAt>().enabled = true; } }
private void MouseButtonUp() { //Fem release tenint un objecte del inventari seleccionat if(_inventory.Showing()){ GameObject invObj = _inventory.GetSelected(); Vector3 mousePos = new Vector3(Input.mousePosition.x,Input.mousePosition.y,0); GameObject otherObj = _inventory.OverObject(mousePos); if(invObj!=otherObj){ if(otherObj!=null){//Estem intentant combinar objectes que son dins l'inventari }else{//Estem intentant combinar amb un objecte de l'escena Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if( Physics.Raycast(ray, out hit) ){ if(hit.collider.gameObject.GetComponent<interactuable>()) { //Cridar a la funcio d combinar objectes //Debug.Log ("Desti de combinacio: " + hit.collider.gameObject); interactuable interDesti = hit.collider.gameObject.GetComponent<interactuable>(); bool isGood = interDesti.comprobarInteraccio(invObj); if(isGood){ //Debug.Log("Combinacio Correcta!"); Application.LoadLevel ("end"); } } } } } if(invObj){ invObj.transform.position = new Vector3(1,1,0); invObj.guiTexture.pixelInset= new Rect(0,18-100,64,64); invObj.guiTexture.color = new Color(0.5f,0.5f,0.5f,0.5f); _inventory.Hide(); _inventory.SetSelected(null); } } //Fem release tenint un menu contextual desplegat if(_interactuable!=null) { Vector3 cPos = Input.mousePosition - _interactuable.GetScreenPosition(); for(int i=0;i<_interactuable.Actions.Length;i++) { //Comprovar distancia del puntero al las opciones Vector3 aPos = new Vector3(_interactuable.Actions[i].guiTexture.pixelInset.x+32, _interactuable.Actions[i].guiTexture.pixelInset.y+32,0); float aDist = Vector3.Distance(aPos,cPos); if(aDist<32) { _interactuable.Actions[i].GetComponent<Action>().Do(); } } GameObject.DestroyObject(cRaster); _interactuable.HideMenu(); _interactuable = null; cam.GetComponent<customLookAt>().enabled=true; } }
private void MouseButtonDown() { Ray ray = cam.ScreenPointToRay(Input.mousePosition); int count = Input.touchCount; if( count == 1 ) { Touch touch = Input.GetTouch(0); ray = cam.ScreenPointToRay( new Vector3( touch.position.x, touch.position.y ) ); } GameObject invObj=null; if(_inventory.Showing()){ invObj = _inventory.OverObject(new Vector3(Input.mousePosition.x,Input.mousePosition.y,0)); _inventory.SetSelected(invObj); } RaycastHit hit; if( Physics.Raycast(ray, out hit) && invObj==null ) { if(hit.collider.gameObject == gameObject) { _inventory.Toggle(); } else if(hit.collider.gameObject.GetComponent<interactuable>()) { //TODO:Desactivar script camera // targetLocation = thisTransform.position; cam.GetComponent<customLookAt>().enabled=false; _interactuable = hit.collider.gameObject.GetComponent<interactuable>(); Vector3 screenPos = cam.WorldToScreenPoint(hit.collider.gameObject.transform.position); _interactuable.ShowMenu(screenPos); _raster.particleSystem.Stop(); cRaster = (GameObject)GameObject.Instantiate(_raster,hit.collider.gameObject.transform.position,new Quaternion(0,0,0,0)); cRaster.SetActive(true); _inventory.Hide(); } else { if(invObj==null) _inventory.Hide(); float touchDist = (transform.position - hit.point).magnitude; if( touchDist > minimumDistanceToMove ) { targetLocation = hit.point; } Quaternion quat = Quaternion.AngleAxis(270,new Vector3(1,0,0)); GameObject.Instantiate(onClickCursor,targetLocation,quat); } } }