using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MacaAnimacija : MonoBehaviour
{
    public AudioClip macaz;
    public AudioClip ljuta;
    public AudioSource zvuk;
    public AudioSource zvuk2;
    public Animator maca;
    public Rigidbody rbody;
    
    public float speed = 6.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;

    private Vector3 moveDirection = Vector3.zero;
    private CharacterController controller;


    void Start()
    {
        maca = GetComponent<Animator>();
        rbody = GetComponent<Rigidbody>();
        rbody.velocity = transform.forward *Input.GetAxis("Vertical") * 90f * Time.deltaTime;
        controller = GetComponent<CharacterController>();
        zvuk = GetComponent<AudioSource>();
    }

    void Update()
    {
        //if (Input.GetKeyDown("w"))
        //{
        //    maca.Play("walk", -1, 0f);
        //}
        if (Input.GetKeyUp("space"))
        {
            maca.Play("jump", -1, 0f);
            rbody.AddForce(Vector3.up * 1000f);
            //transform.position += new Vector3(playerSetX, playerJumpHeight, playerSetZ);


        }
        if (Input.GetKeyDown("mouse 1"))
        {
            maca.Play("roar", -1, 0f);
            zvuk.PlayOneShot(macaz);

        }
        if (Input.GetKeyDown("mouse 0"))
        {
            maca.Play("clawsAttackCombo", -1, 0f);
            zvuk2.PlayOneShot(ljuta);
        }
        if (Input.GetKey("left shift"))
        {
            maca.Play("run", -1, 0f);
        }

        
        //rbody.velocity = transform.forward *Input.GetAxis("Vertical") * 90f * Time.deltaTime;
        
        maca.SetFloat("inputV",Input.GetAxis("Vertical") * 50f * Time.deltaTime);

        if (controller.isGrounded)
        {
            // We are grounded, so recalculate
            // move direction directly from axes

            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection = moveDirection * speed;

            if (Input.GetButton("Jump"))
            {
                moveDirection.y = jumpSpeed;
            }
        }

        // Apply gravity
        moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);

        // Move the controller
        controller.Move(moveDirection * Time.deltaTime);

    }
}
