Ejemplo n.º 1
0
        private void HandleDrag(Vector3 initialMousePos, Vector3 currMousePos, float angle)
        {
            if (ball.IsAtRest())
            {
                gameObject.SetActive(true);
                var cameraDirection = Vector3.ProjectOnPlane(relativeCamera.transform.forward, Vector3.up);
                var rotation        = Quaternion.LookRotation(cameraDirection) * Quaternion.Euler(0, angle, 0);
                transform.rotation = rotation;

                var newScale = transform.localScale;
                newScale.z           = Math.Min(maxZScale, ball.calculateForce(currMousePos - new Vector3(Screen.width / 2, Screen.height / 2)) * lengthScaleFactor);
                transform.localScale = newScale;
                material.SetTextureScale("_MainTex", new Vector3(transform.localScale.x, transform.localScale.z * 4));
            }
        }
Ejemplo n.º 2
0
        private void HandleDragPerform(InputAction.CallbackContext context)
        {
            var currMousePos = context.ReadValue <Vector2>();
            // Offset of mouse from center of screen
            var   mouseCenterOffset = currMousePos - new Vector2(Screen.width / 2.0f, Screen.height / 2.0f);
            float angle             = -Mathf.Atan2(mouseCenterOffset.y, mouseCenterOffset.x) * 180 / Mathf.PI + 90;

            if (ball.IsAtRest())
            {
                gameObject.SetActive(true);
                var cameraDirection = Vector3.ProjectOnPlane(relativeCamera.transform.forward, Vector3.up);
                var rotation        = Quaternion.LookRotation(cameraDirection) * Quaternion.Euler(90, angle, 0);
                transform.rotation = rotation;
                slider.value       = ball.calculateForce(mouseCenterOffset);

                fillImage.color = Color.Lerp(minStrengthColor, maxStrengthColor, slider.value / slider.maxValue);
            }
        }