Ejemplo n.º 1
0
    IEnumerator Shoot()
    {
        //Stop movement and show targeting line
        movement.enabled = false;
        line.enabled     = true;
        line.SetPositions(defaultPoints);

        //Spawn ball and place it on player
        BallMovement ball = PoolManager.Instance.GetPooledObject(PoolID.Ball).GetComponent <BallMovement>();

        ball.transform.SetPositionAndRotation(spawnPoint.position, Quaternion.identity);
        yield return(new WaitUntil(() => Input.GetMouseButtonDown(0)));

        Vector3 direction = Vector3.up;
        Vector3 tapPosition;

        while (Input.GetMouseButton(0))
        {
            tapPosition   = mainCamera.ScreenToWorldPoint(Input.mousePosition);
            tapPosition.z = 0;

            if (Vector3.Angle(Vector3.up, tapPosition - spawnPoint.position) < MaxAngle) //Prevents player from shooting ball too horizontally or downwards
            {
                direction = tapPosition - spawnPoint.position;
                line.SetPosition(1, myTransform.InverseTransformPoint(tapPosition));
            }

            yield return(null);
        }

        //Enables movement and hide targeting line
        movement.enabled = true;
        line.enabled     = false;

        //Shoot ball in xy direction
        direction.z = 0;
        ball.Shoot(direction.normalized);
    }