private void Update() { if (m_interactingInteractive == null) { var verticalMovement = m_inputService.GetVerticalMovementDirection(); var horizontalMovement = m_inputService.GetHorizontalMovementDirection(); var axisAlignedMovement = new Vector2(horizontalMovement, verticalMovement); var forwardDirection = new Vector3(axisAlignedMovement.x, 0f, axisAlignedMovement.y); transform.Translate(forwardDirection * m_moveSpeed * Time.deltaTime, Space.Self); m_animator.SetFloat("MoveSpeed", axisAlignedMovement.magnitude); FlipCharacter(horizontalMovement); if (!m_timeOfLastAutoSort.HasValue || (DateTime.UtcNow - m_timeOfLastAutoSort.Value).TotalSeconds > AUTO_SORT_SECONDS) { SortInteractivesByDistance(); m_timeOfLastAutoSort = DateTime.UtcNow; } if (m_inputService.GetInteractButtonPressed() == true) { m_selectedInteractive?.BeginInteraction(this); } } }
private void Update() { if (InputUtility.DidTouchBegin()) { var ray = Camera.main.ScreenPointToRay(Input.mousePosition); m_plane.Raycast(ray, out float enter); var intersect = ray.GetPoint(enter); Debug.DrawLine(ray.origin, intersect, Color.green, 15f); if (Physics.RaycastNonAlloc(ray, m_raycastHits, Mathf.Infinity, m_layerMask) > 0) { var raycastHitLocation = m_raycastHits[0].collider.bounds.min; m_interactiveObject = m_raycastHits[0].collider.GetComponent <InteractiveObject>(); if (m_interactiveObject != null) { Vector3 position = new Vector3(raycastHitLocation.x, HEIGHT_OFFSET, raycastHitLocation.z); RegisterEvent(m_interactiveObject.gameEventType, position); } } m_interactiveObject?.BeginInteraction(this); } else if (InputUtility.DidTouchEnd()) { m_interactiveObject?.ReleaseInteraction(); } }