Пример #1
0
    void ShootArrow()
    {
        GameObject playerObject = CurrentLevelVariableManagement.GetPlayerReference();

        float preHeading = attachedCharacterInput.GetActualClass().GetFacingDirection() == 1 ? 0 : 180;

        //Apparently there is some issue with the bow's position when attached to the player object, because it is always (0, 0, 0).  This fixes it.
        GameObject instantiatedArrow = (GameObject)(Instantiate(arrow, attachedCharacterInput.GetActualClass().gameObject.transform.position + new Vector3(1.2f, 0, 0) * attachedCharacterInput.GetActualClass().GetFacingDirection(), Quaternion.identity));

        ProjectileScript instantiatedArrowScript = instantiatedArrow.GetComponent <ProjectileScript> ();

        Vector3 positionToFireToward;
        float   accuracy;

        if (attackPlayer)
        {
            positionToFireToward = playerObject.transform.position;
            accuracy             = 30;
        }
        else
        {
            Vector3 shootDirection;
            shootDirection       = Input.mousePosition;
            shootDirection.z     = 0.0f;
            shootDirection       = Camera.main.ScreenToWorldPoint(shootDirection);
            shootDirection       = shootDirection - transform.position;
            positionToFireToward = shootDirection;
            accuracy             = 0;
        }

        instantiatedArrowScript.InitializeProjectileWithThresholdAndDeviation(positionToFireToward, 12, preHeading, 30, accuracy, attackPowerStrength);
    }