Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour {
- // Componentes
- private Animator anim;
- private CharacterController controller;
- // Variáveis de movimentação
- private Vector3 moveDirection = Vector3.zero;
- [SerializeField] private float moveSpeed = 3.0f;
- [SerializeField] private float jumpSpeed = 6.0f;
- [SerializeField] private float turnSpeed = 4.0f;
- private float gravity = 20.0f;
- private bool attacking = false;
- [SerializeField] private GameObject playerAttackArea;
- public int damage = 25;
- [SerializeField] private GameObject cameraController;
- public GameObject bloodEffect;
- public GameObject bloodSpawn;
- void Start ()
- {
- anim = GetComponent<Animator>();
- controller = GetComponent<CharacterController>();
- Screen.lockCursor = true;
- Cursor.visible = false;
- Cursor.lockState = CursorLockMode.Locked;
- }
- void Update () {
- anim.SetFloat("Speed", Input.GetAxis("Vertical"));
- //transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime);
- if (controller.isGrounded) // Se o jogador está no chão
- {
- moveDirection = Vector3.forward * Input.GetAxis("Vertical");
- moveDirection = transform.TransformDirection(moveDirection);
- moveDirection *= moveSpeed;
- if (Input.GetButtonDown("Jump") && !attacking)
- {
- moveDirection.y = jumpSpeed;
- anim.SetBool("Jumping", true);
- }
- else if (Input.GetButtonDown("Attack") && !attacking)
- {
- anim.SetBool("Attacking", true);
- attacking = true;
- }
- else
- {
- anim.SetBool("Jumping", false);
- }
- }
- moveDirection.y -= gravity * Time.deltaTime; // Aplica gravidade em Y
- /*if (attacking) // Remove a movimentação durante o ataque
- {
- moveDirection.x = 0.0f;
- moveDirection.z = 0.0f;
- }*/
- controller.Move(moveDirection * Time.deltaTime);
- float rotX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * turnSpeed * Time.timeScale;
- float rotY = cameraController.transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * turnSpeed * Time.timeScale;
- transform.localEulerAngles = new Vector3(0f, rotX, 0f);
- cameraController.transform.localEulerAngles = new Vector3(rotY, 0f, 0f);
- }
- public void StopAttacking()
- {
- anim.SetBool("Attacking", false);
- attacking = false;
- playerAttackArea.SetActive(false);
- }
- public void ActivateTrigger()
- {
- playerAttackArea.SetActive(true);
- }
- private void OnTriggerEnter(Collider other)
- {
- if (gameObject.tag == "Player" && other.gameObject.name == "EnemyAttackCollider")
- {
- GetComponent<LifeManager>().changeHP(-5);
- Debug.Log("OnTriggerEnter do Player! " + gameObject.name + " / " + other.gameObject.name);
- other.gameObject.SetActive(false);
- GameObject copy = Instantiate(bloodEffect, bloodSpawn.transform.position, bloodSpawn.transform.rotation);
- copy.transform.parent = bloodSpawn.transform;
- copy.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement