Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        playerPosition = GameObject.Find("Player").GetComponent <Transform>();

        Vector2 mousePos  = MouseUtils.GetMousePosition();
        float   aimAngle  = MouseUtils.GetAimAngle(transform.position) * Mathf.Rad2Deg + 180;
        int     stepAngle = Mathf.RoundToInt(360f / rotationSteps);

        currentStep = Mathf.RoundToInt(aimAngle / stepAngle) % 4 * stepAngle;

        switch (currentStep)
        {
        default:
        case 0:
        case 360:
            playerBody.sprite = rSprite_Torso;
            playerHead.sprite = rSprite_Head;
            break;

        case 45:
            playerBody.sprite = ruSprite_Torso;
            playerHead.sprite = ruSprite_Head;
            break;

        case 90:
            playerBody.sprite = uSprite_Torso;
            playerHead.sprite = uSprite_Head;
            break;

        case 135:
            playerBody.sprite = ulSprite_Torso;
            playerHead.sprite = ulSprite_Head;
            break;

        case 180:
            playerBody.sprite = lSprite_Torso;
            playerHead.sprite = lSprite_Head;
            break;

        case 225:
            playerBody.sprite = ldSprite_Torso;
            playerHead.sprite = ldSprite_Head;
            break;

        case 270:
            playerBody.sprite = dSprite_Torso;
            playerHead.sprite = dSprite_Head;
            break;

        case 315:
            playerBody.sprite = drSprite_Torso;
            playerHead.sprite = drSprite_Head;
            break;
        }
    }