Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Random = UnityEngine.Random;
  5.  
  6.  
  7. public class EnemyScript : MonoBehaviour
  8. {
  9. public float speed =5f;
  10. public float rotate_Speed = 50f;
  11.  
  12. public bool canShoot;
  13. public bool canRotate;
  14. private bool canMove = true;
  15.  
  16. public float bound_X = -11f;
  17. public float bound_X2 = 11f;
  18. public float bound_Y = -11f;
  19. public float bound_Y2 = 11f;
  20.  
  21.  
  22. public Transform attack_Point;
  23. public GameObject bulletPrefab;
  24.  
  25. private float direcaoX, direcaoY, dir;
  26. public bool aleatorio;
  27.  
  28. void Awake()
  29. {
  30.  
  31. }
  32.  
  33.  
  34. void Update()
  35. {
  36. Move();
  37. RotateEnemy();
  38. }
  39.  
  40. void Start()
  41. {
  42. direcaoX = Random.Range(-1f, 1f);
  43. direcaoY = 1 - Mathf.Abs(direcaoX);
  44. dir = Random.Range(-1, 2);
  45. while (dir == 0)
  46. dir = Random.Range(-1, 2);
  47. direcaoY *= dir;
  48.  
  49. if(canShoot)
  50. Invoke("StartShooting", Random.Range(1f,3f));
  51.  
  52.  
  53.  
  54. if(canRotate)
  55. {
  56. if(Random.Range(0,2) > 0)
  57. {
  58. rotate_Speed = Random.Range(rotate_Speed, rotate_Speed +20f);
  59. rotate_Speed *= -1f;
  60.  
  61. }
  62.  
  63. }
  64.  
  65.  
  66. }
  67.  
  68. void Move ()
  69.  
  70. {
  71.  
  72.  
  73. if(canMove)
  74. {
  75. Vector3 temp = transform.position;
  76.  
  77. if(aleatorio){
  78. temp.x -= Time.deltaTime * direcaoX;
  79. temp.y -= Time.deltaTime * direcaoY;
  80. transform.position = temp;
  81. }
  82.  
  83. else {
  84. temp.x -= Time.deltaTime;
  85. transform.position = temp;
  86. }
  87.  
  88. if(temp.x < bound_X || temp.x > bound_X2 ||temp.y < bound_Y ||temp.y > bound_Y2)
  89. gameObject.SetActive(false);
  90.  
  91. }
  92. }
  93.  
  94. void RotateEnemy(){
  95. if(canRotate)
  96. {
  97. transform.Rotate(new Vector3(0f, 0f, rotate_Speed * Time.deltaTime), Space.World);
  98. }
  99. }
  100.  
  101. void StartShooting() {
  102.  
  103. GameObject bullet = Instantiate(bulletPrefab, attack_Point.position, Quaternion.identity);
  104. bullet.GetComponent<BulletScript>().is_EnemyBullet = true;
  105.  
  106. if(canShoot)
  107. Invoke("StartShooting", Random.Range(1f,3f));
  108.  
  109. }
  110.  
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement