Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.1 kB
3
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;

public class PlayerCombat : MonoBehaviour
{

    [SerializeField] private Animator anim;
    [SerializeField] private Transform playervisual;

    private Vector3 playerscale;

    private const string WALK_PARAM = "IsWalking";
    private const string ATTACK_PARAM = "IsAttacking";
    // Start is called before the first frame update
    void Start()
    {
        playerscale = playervisual.transform.localScale;
    }

    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal");

        anim.SetBool(WALK_PARAM, x != 0);

        if (Input.GetKeyDown(KeyCode.F))
        {
            anim.SetTrigger(ATTACK_PARAM);
        }

        if (x > 0)
        {
            playervisual.transform.localScale = playerscale;
        }
        else if (x < 0)
        {
            playervisual.transform.localScale = new Vector3(-playerscale.x, playerscale.y, playerscale.z);
        }

    }
}
Leave a Comment