Beispiel #1
0
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            ShootToDirection(ScreenPointToPosition2D.GetWorldPosition2D(Input.mousePosition, transform.position.z));
        }
#endif

        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            ShootToDirection(ScreenPointToPosition2D.GetWorldPosition2D(Input.GetTouch(0).position, transform.position.z));
        }
    }
Beispiel #2
0
    void RotateToDirection(Vector3 direction)
    {
        Vector3 newRotation = transform.rotation.eulerAngles;

        newRotation.z = ScreenPointToPosition2D.GetZRotation2D(transform.position, direction);

        if (newRotation.z < minimumAngle)
        {
            newRotation.z = minimumAngle;
        }
        if (newRotation.z > maximumAngle)
        {
            newRotation.z = maximumAngle;
        }

        transform.rotation = Quaternion.Euler(newRotation);
    }