Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = UnityEngine.Random;
- public class EnemyScript : MonoBehaviour
- {
- public float speed =5f;
- public float rotate_Speed = 50f;
- public bool canShoot;
- public bool canRotate;
- private bool canMove = true;
- public float bound_X = -11f;
- public float bound_X2 = 11f;
- public float bound_Y = -11f;
- public float bound_Y2 = 11f;
- public Transform attack_Point;
- public GameObject bulletPrefab;
- private float direcaoX, direcaoY, dir;
- public bool aleatorio;
- void Awake()
- {
- }
- void Update()
- {
- Move();
- RotateEnemy();
- }
- void Start()
- {
- direcaoX = Random.Range(-1f, 1f);
- direcaoY = 1 - Mathf.Abs(direcaoX);
- dir = Random.Range(-1, 2);
- while (dir == 0)
- dir = Random.Range(-1, 2);
- direcaoY *= dir;
- if(canShoot)
- Invoke("StartShooting", Random.Range(1f,3f));
- if(canRotate)
- {
- if(Random.Range(0,2) > 0)
- {
- rotate_Speed = Random.Range(rotate_Speed, rotate_Speed +20f);
- rotate_Speed *= -1f;
- }
- }
- }
- void Move ()
- {
- if(canMove)
- {
- Vector3 temp = transform.position;
- if(aleatorio){
- temp.x -= Time.deltaTime * direcaoX;
- temp.y -= Time.deltaTime * direcaoY;
- transform.position = temp;
- }
- else {
- temp.x -= Time.deltaTime;
- transform.position = temp;
- }
- if(temp.x < bound_X || temp.x > bound_X2 ||temp.y < bound_Y ||temp.y > bound_Y2)
- gameObject.SetActive(false);
- }
- }
- void RotateEnemy(){
- if(canRotate)
- {
- transform.Rotate(new Vector3(0f, 0f, rotate_Speed * Time.deltaTime), Space.World);
- }
- }
- void StartShooting() {
- GameObject bullet = Instantiate(bulletPrefab, attack_Point.position, Quaternion.identity);
- bullet.GetComponent<BulletScript>().is_EnemyBullet = true;
- if(canShoot)
- Invoke("StartShooting", Random.Range(1f,3f));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement