IEnumerator PickUpState() { var pickups = pickupsSpotted; if (pickups.Count == 0) { StartCoroutine(DefaultState()); yield break; } var pickup = pickups[0]; float countdown = 2f; while (countdown > 0f) { countdown -= Time.deltaTime; if (pickup.IsHeld) { StartCoroutine(DefaultState()); yield break; } movement.Move = SteerSensor.GetSteeredDirection(pickup.transform.position - transform.position); movement.Face = movement.Move; if (InteractionRange.IsDetected(pickup.gameObject)) { movement.PickUp(pickup); break; } yield return(null); } StartCoroutine(DefaultState()); }
void Update() { var horiz = Input.GetAxis("Horizontal"); var vert = Input.GetAxis("Vertical"); cc.Move = new Vector3(horiz, 0f, vert); // Project mouse position onto worlds plane at y=0 var mousePosScreen = Input.mousePosition; var camPosition = Camera.main.transform.position; var camForward = Camera.main.transform.forward; var camDepthToGroundPlane = -camPosition.y / camForward.y; mousePosScreen.z = camDepthToGroundPlane; var mousePosGroundPlane = Camera.main.ScreenToWorldPoint(mousePosScreen); cc.Face = (mousePosGroundPlane - transform.position).normalized; // Pickup the pickup if its in range var pickup = InteractionRange.GetNearestByComponent <Holdable>(); if (pickup != null && !pickup.IsHeld) { cc.PickUp(pickup); } }