Advertisement
Guest User

aaaaa

a guest
Dec 6th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6. // Componentes
  7. private Animator anim;
  8. private CharacterController controller;
  9.  
  10. // Variáveis de movimentação
  11. private Vector3 moveDirection = Vector3.zero;
  12. [SerializeField] private float moveSpeed = 3.0f;
  13. [SerializeField] private float jumpSpeed = 6.0f;
  14. [SerializeField] private float turnSpeed = 4.0f;
  15. private float gravity = 20.0f;
  16.  
  17. private bool attacking = false;
  18. [SerializeField] private GameObject playerAttackArea;
  19. public int damage = 25;
  20.  
  21. [SerializeField] private GameObject cameraController;
  22.  
  23. public GameObject bloodEffect;
  24. public GameObject bloodSpawn;
  25.  
  26. void Start ()
  27. {
  28. anim = GetComponent<Animator>();
  29. controller = GetComponent<CharacterController>();
  30. Screen.lockCursor = true;
  31. Cursor.visible = false;
  32. Cursor.lockState = CursorLockMode.Locked;
  33. }
  34.  
  35. void Update () {
  36. anim.SetFloat("Speed", Input.GetAxis("Vertical"));
  37. //transform.Rotate(Vector3.up * Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime);
  38.  
  39. if (controller.isGrounded) // Se o jogador está no chão
  40. {
  41. moveDirection = Vector3.forward * Input.GetAxis("Vertical");
  42. moveDirection = transform.TransformDirection(moveDirection);
  43. moveDirection *= moveSpeed;
  44.  
  45. if (Input.GetButtonDown("Jump") && !attacking)
  46. {
  47. moveDirection.y = jumpSpeed;
  48. anim.SetBool("Jumping", true);
  49. }
  50. else if (Input.GetButtonDown("Attack") && !attacking)
  51. {
  52. anim.SetBool("Attacking", true);
  53. attacking = true;
  54. }
  55. else
  56. {
  57. anim.SetBool("Jumping", false);
  58. }
  59. }
  60.  
  61. moveDirection.y -= gravity * Time.deltaTime; // Aplica gravidade em Y
  62. /*if (attacking) // Remove a movimentação durante o ataque
  63. {
  64. moveDirection.x = 0.0f;
  65. moveDirection.z = 0.0f;
  66. }*/
  67. controller.Move(moveDirection * Time.deltaTime);
  68.  
  69. float rotX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * turnSpeed * Time.timeScale;
  70. float rotY = cameraController.transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * turnSpeed * Time.timeScale;
  71. transform.localEulerAngles = new Vector3(0f, rotX, 0f);
  72. cameraController.transform.localEulerAngles = new Vector3(rotY, 0f, 0f);
  73. }
  74.  
  75. public void StopAttacking()
  76. {
  77. anim.SetBool("Attacking", false);
  78. attacking = false;
  79. playerAttackArea.SetActive(false);
  80. }
  81.  
  82. public void ActivateTrigger()
  83. {
  84. playerAttackArea.SetActive(true);
  85. }
  86.  
  87. private void OnTriggerEnter(Collider other)
  88. {
  89. if (gameObject.tag == "Player" && other.gameObject.name == "EnemyAttackCollider")
  90. {
  91. GetComponent<LifeManager>().changeHP(-5);
  92. Debug.Log("OnTriggerEnter do Player! " + gameObject.name + " / " + other.gameObject.name);
  93. other.gameObject.SetActive(false);
  94. GameObject copy = Instantiate(bloodEffect, bloodSpawn.transform.position, bloodSpawn.transform.rotation);
  95. copy.transform.parent = bloodSpawn.transform;
  96. copy.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement