public void Awake() { cState = controllerState.OFF_ALL; dropState = dropBtnState.OFFLINE; deliveryState = limbDeliveryState.SEARCHING; dropInvoked = false; liftingLimb = false; uiScreenSwitched = false; clawXStart = claw.transform.localPosition.x; clawZStart = claw.transform.localPosition.z; rope = GetComponent <LineRenderer> (); limbCount = 0; beamRotationY = 0f; beamRotationX = 180f; targetRotationX = 0f; targetRotationY = 0f; clawExtension = 0f; targetExtension = 0f; rotationStateX = 0f; rotationStateY = 0f; clawHeight = claw.transform.localPosition.y; restHeight = clawHeight; bottomHeight = clawHeight + armLength; currentDrop = 0.0f; targetDrop = 0.0f; audio = GetComponent <AudioSource> (); }
public void Update() { switch (deliveryState) { case (limbDeliveryState.SEARCHING): if (!dropInvoked) { audio.clip = rotate; switch (cState) { case (controllerState.ON_TOP): targetExtension = Mathf.Clamp(targetExtension + 0.01f, -0.5f, 0.5f); if (!audio.isPlaying) { audio.Play(); } break; case (controllerState.ON_LEFT): rotationStateY -= 0.02f * (Mathf.Sign(targetExtension)); if (!audio.isPlaying) { audio.Play(); } break; case (controllerState.ON_RIGHT): rotationStateY += 0.02f * (Mathf.Sign(targetExtension)); if (!audio.isPlaying) { audio.Play(); } break; case (controllerState.ON_BOTTOM): targetExtension = Mathf.Clamp(targetExtension - 0.01f, -0.5f, 0.5f); if (!audio.isPlaying) { audio.Play(); } break; default: audio.Stop(); break; } } if (dropState == dropBtnState.LIVE) { if (targetDrop == 0) { audio.Stop(); audio.clip = drop; audio.Play(); if (!uiScreenSwitched) { uiScreenSwitched = true; RCUIScreen.StartDrop(); } RaycastHit rayInfo = new RaycastHit(); Physics.Raycast(new Ray(claw.transform.position + new Vector3(0, -2, 0), Vector3.down), out rayInfo); if (rayInfo.transform != null) { Debug.Log("raycast found object " + rayInfo.transform.gameObject.name); if (rayInfo.collider.gameObject.layer == LayerMask.NameToLayer("BodyPart")) { grabbedLimb = rayInfo.transform; } } else { Debug.Log("raycast missed all objects"); } targetDrop = 1; dropInvoked = true; Invoke("InvokedOnDrop", 3f); } else { if (grabbedLimb != null) { targetExtension = 0; liftingLimb = true; } targetDrop = 0; deliveryState = limbDeliveryState.LIFTING; } dropState = dropBtnState.OFFLINE; } break; case (limbDeliveryState.LIFTING): if (!audio.clip == retract) { audio.Stop(); audio.clip = retract; } if (!audio.isPlaying) { audio.Play(); } if (Mathf.Abs(currentDrop - targetDrop) < float.Epsilon) { if (targetDrop == 1) { if (grabbedLimb != null) { limbOffset = grabbedLimb.position - claw.transform.position; grabbedLimb.GetComponentInParent <Rigidbody> ().isKinematic = true; } } else if (targetDrop == 0) { if (grabbedLimb != null) { if (limbLock.AcceptLimb(grabbedLimb.gameObject)) { limbCount++; if (limbCount == 1) { GameController.instance.voice.RequestPlayClip(11); } if (limbCount == 2) { GameController.instance.voice.RequestPlayClip(15); } if (limbCount == 3) { GameController.instance.voice.RequestPlayClip(16); } if (limbCount == 4) { GameController.instance.voice.RequestPlayClip(17); } if (limbCount == 5) { GameController.instance.voice.RequestPlayClip(18); } deliveryState = limbDeliveryState.ROTATING_UP; rotationStateX = 3f; } else { grabbedLimb.GetComponentInParent <Rigidbody> ().isKinematic = false; grabbedLimb = null; deliveryState = limbDeliveryState.SEARCHING; liftingLimb = false; if (uiScreenSwitched) { uiScreenSwitched = false; RCUIScreen.StopDrop(); } } } else { if (uiScreenSwitched) { uiScreenSwitched = false; RCUIScreen.StopDrop(); } deliveryState = limbDeliveryState.SEARCHING; } } } break; case (limbDeliveryState.ROTATING_UP): if (Mathf.Abs(beamRotationX - targetRotationX) < float.Epsilon) { deliveryState = limbDeliveryState.PUSHING; targetDrop = 0.5f; } break; case (limbDeliveryState.PUSHING): if (Mathf.Abs(currentDrop - targetDrop) < float.Epsilon) { Destroy(grabbedLimb.gameObject); liftingLimb = false; grabbedLimb = null; deliveryState = limbDeliveryState.RETRACTING; targetDrop = 0.0f; } break; case (limbDeliveryState.RETRACTING): if (Mathf.Abs(currentDrop - targetDrop) < float.Epsilon) { deliveryState = limbDeliveryState.ROTATING_DOWN; rotationStateX = 0f; } break; case (limbDeliveryState.ROTATING_DOWN): if (Mathf.Abs(beamRotationX - targetRotationX) < float.Epsilon) { deliveryState = limbDeliveryState.SEARCHING; RCUIScreen.StopDrop(); uiScreenSwitched = false; } break; } targetRotationX = rotationStateX * 60 % float.MaxValue - 180f; targetRotationY = rotationStateY * 60 % float.MaxValue; beamRotationY = (beamRotationY + Mathf.Clamp(targetRotationY - beamRotationY, -5, 5)) % float.MaxValue; clawExtension = clawExtension + Mathf.Clamp(targetExtension - clawExtension, -0.01f, 0.01f); currentDrop = (currentDrop + Mathf.Clamp(targetDrop - currentDrop, -0.01f, 0.01f)); if (deliveryState == limbDeliveryState.ROTATING_UP || deliveryState == limbDeliveryState.ROTATING_DOWN) { beamRotationX = (beamRotationX + Mathf.Clamp(targetRotationX - beamRotationX, -2, 2)); } }