public void Release() { hook.showDropSite(false); Transform dropPoint = hook.dropPoint; hook.empty = false; transform.parent = null; transform.position = dropPoint.position; CheckLightActive checkScript = GetComponentInChildren <CheckLightActive>(); if (checkScript != null) { audioManager.Play((int)AudioManager.SoundGeneral.LIGHT_CLICK); checkScript.Activate(); } else { mLight.enabled = true; } Rotable rot = gameObject.GetComponent <Rotable>(); if (rot != null) { rot.released(); } }
private void PC() { if (!moveScript.interacting) { if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Joystick1Button4)) { if (carrying && canDrop) { Movable carriedObj = GetComponentInChildren <Movable>(); carriedObj.hook = dropSite; carriedObj.Release(); carrying = false; } else if (!carrying) { //Cast a ray from the camera to his forward Ray ray = new Ray(cam.transform.position, cam.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxDistance)) { Movable moveScript = hit.transform.gameObject.GetComponent <Movable>(); if (moveScript != null && moveScript.isActiveAndEnabled) { Rotable rot = hit.transform.GetComponent <Rotable>(); if (rot != null && rot.isIdle()) { moveScript.Carry(cam.transform, carryOffset); carrying = true; } } } } else { Debug.Log("Cant drop"); } } else if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Joystick1Button5)) { if (!carrying) { //Cast a ray from the camera to his forward Ray ray = new Ray(cam.transform.position, cam.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxDistance)) { Rotable rotateScript = hit.transform.gameObject.GetComponent <Rotable>(); if (rotateScript != null && rotateScript.isActiveAndEnabled) { rotateScript.clicked(); } } } } } }
// Start is called before the first frame update void Start() { movableComponent = gameObject.GetComponent <Movable>(); rotableComponent = gameObject.GetComponent <Rotable>(); }
// Start is called before the first frame update void Start() { movableComponent = gameObject.GetComponent <Movable>(); rotableComponent = gameObject.GetComponent <Rotable>(); keys = new KeyCode[] { upKey, downKey, leftKey, rightKey }; }
private void Android() { if (Input.touchCount > 0) { float dt = Time.deltaTime; Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { startTime = Time.time; startPos = touch.position; } else if (touch.phase == TouchPhase.Ended) { endTime = Time.time; endPos = touch.position; swipeDistance = (endPos - startPos).magnitude; swipeTime = (endTime - startTime); if (swipeTime <= minTimeToBeSwipe) { if (carrying && canDrop) { Movable carriedObj = GetComponentInChildren <Movable>(); carriedObj.hook = dropSite; carriedObj.Release(); carrying = false; } else if (!carrying) { //Cast a ray from the camera to his forward Ray ray = new Ray(cam.transform.position, cam.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxDistance)) { Movable moveScript = hit.transform.gameObject.GetComponent <Movable>(); if (moveScript != null && moveScript.isActiveAndEnabled) { Rotable rot = hit.transform.GetComponent <Rotable>(); if (rot != null && rot.isIdle()) { moveScript.Carry(cam.transform, carryOffset); carrying = true; } } } } else { Debug.Log("Cant drop"); } } } else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { swipeTime = (Time.time - startTime); if (swipeTime > minTimeToBeSwipe) { if (!carrying) { //Cast a ray from the camera to his forward Ray ray = new Ray(cam.transform.position, cam.transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxDistance)) { Rotable rotateScript = hit.transform.gameObject.GetComponent <Rotable>(); if (rotateScript != null && rotateScript.isActiveAndEnabled) { rotateScript.clickedAndroid(touch); } } } } } } }