using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movplayer : MonoBehaviour
{
Player player;
Rigidbody rigid;
Animator anim;
public float Velocidade = 10;
public float VeloCorre = 15;
public float Veloagachado = 07;
public float ForcaPulo = 250;
public float ForcaGravidade = 0;
public LayerMask chaoLayer;
public float raycastLength = 0.9f;
public bool Chao;
public bool Stealth;
public bool Ataque = false; //Animação
public bool Atacado = false; //Animação
public GameObject tiroPrefab;
// Use this for initialization
void Start()
{
//Vector3 ForcaGravidadeS = new Vector3(0, ForcaGravidade, 0);
//Physics.gravity = ForcaGravidadeS;
rigid = GetComponent<Rigidbody>();
anim = GetComponentInChildren<Animator>();
player = GetComponentInChildren<Player>();
}
// 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);
rigid.velocity = movVer * Velocidade * transform.forward;
Vector3 rotacao = transform.rotation.eulerAngles;
rotacao.y += movHor * Velocidade;
transform.rotation = Quaternion.Euler(rotacao);
anim.SetFloat("Velocidade", Mathf.Abs(movHor + movVer));
if (Input.GetKeyDown(KeyCode.Mouse1))
{
player.municao--;
GameObject NovoTiro = (GameObject)Instantiate(tiroPrefab, transform.position + (new Vector3(0, 2, 1)), Quaternion.identity);
Destroy(NovoTiro, 3);
}
if ((Input.GetKeyDown(KeyCode.Space)) && (Chao))
{
pulo();
}
if (Input.GetKeyDown(KeyCode.Mouse0))
{
anim.SetBool("ataque", true);
}
else
{
anim.SetBool("ataque", false);
}
if (Input.GetKeyDown(KeyCode.LeftControl))
{
Velocidade = Veloagachado;
anim.SetBool("agachado", true);
Stealth = true;
}
if (Input.GetKeyUp(KeyCode.LeftControl))
{
Velocidade = 10;
anim.SetBool("agachado", false);
Stealth = false;
}
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
{
Velocidade = VeloCorre;
anim.SetBool("correndo", true);
}
if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
{
Velocidade = 10;
anim.SetBool("correndo", false);
}
}
void pulo()
{
rigid.AddForce(new Vector3(0, ForcaPulo, 0));
Chao = false;
}
private void OnTriggerEnter(Collider col)
{
if (col.tag == "ataqueInimigo")
{
player.vida--;
anim.SetBool("atacado", true);
}
}
private void OnTriggerExit(Collider col)
{
if (col.tag == "ataqueInimigo")
{
anim.SetBool("atacado", false);
}
}
public void FixedUpdate()
{
RaycastHit hit;
Debug.DrawRay(transform.position, Vector3.down * raycastLength, Color.blue);
if (Physics.Raycast(transform.position, Vector3.down, out hit, raycastLength , chaoLayer))
{
Chao = true;
//anim.SetBool("chao", true);
}else
{
Chao = false;
}
}
}