using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControler : MonoBehaviour
{
Hud hud;
Rigidbody rigid;
Animator anim;
public float Velocidade = 10;
public float ForcaPulo;
public float Correr = 15;
public float Agachar = 5;
public bool stealth;
bool chao;
public LayerMask chaoLayer;
public bool ataque = false; //Animação
public bool atacado = false; //Animação
public GameObject ataqueHitbox;
// Use this for initialization
void Start()
{
rigid = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
hud = GetComponent<Hud>();
}
// Update is called once per frame
void Update()
{
float movHor = Input.GetAxis("Horizontal");
float movVer = Input.GetAxis("Vertical");
rigid.velocity = new Vector3(movHor * Velocidade, rigid.velocity.y, movVer * Velocidade);
if (Input.GetKeyDown(KeyCode.Space))
{
rigid.AddForce(new Vector3(0, ForcaPulo, 0));
chao = true;
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
hud.municao = hud.municao - 1;
}
if (Input.GetKeyDown(KeyCode.Mouse0))
{
anim.SetBool("ataque", true);
}
else
{
anim.SetBool("ataque", false);
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
Velocidade = 5;
anim.SetBool("Agachar", true);
stealth = true;
}
if (Input.GetKeyUp(KeyCode.LeftControl))
{
Velocidade = 10;
anim.SetBool("Agachar", false);
stealth = false;
}
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
{
Velocidade = 15;
anim.SetBool("Correr", true);
stealth = false;
}
if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
{
Velocidade = 10;
anim.SetBool("Correr", false);
stealth = false;
}
}
private void OnTriggerEnter(Collider col)
{
if (col.tag == "ataqueInimigo")
{
hud.vida--;
}
}
public void FixedUpdate()
{
RaycastHit hitchao = Physics.Raycast(transform.position, -Vector3.up, 0.9f, chaoLayer);
Debug.DrawRay(transform.position, -Vector3.up, Color.red);
if (hitchao.collider != null)
{
chao = true;
anim.SetBool("chao", true);
}
else
{
chao = false;
anim.SetBool("chao", false);
}
}
}