Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------------
- enemy
- --------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- public float move_speed;
- public Transform enemy;
- public GameObject player;
- void Awake()
- {
- move_speed = (Random.Range(1, 5));
- }
- void Update()
- {
- enemy.position += transform.right * Time.deltaTime * move_speed;
- if (Input.GetMouseButtonDown(0))
- {
- Vector3 MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
- if (MousePos.x < 0.0f)
- {
- Destroy(this.gameObject);
- }
- }
- if (enemy.position.x > -0.35f)
- {
- Destroy(gameObject);
- Destroy(player);
- }
- }
- }
- --------------------------------------------------------------------------------------
- spawn
- --------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class EnemyManager : MonoBehaviour
- {
- public GameObject enemy_prefab;
- public List<GameObject> enemy;
- public float delayBetweenWaves = 15f;
- public int currentWave = 1;
- public Vector3 spawn_point;
- public Vector3 enemy_look;
- public float cellX = 1f;
- public float cellY = 1f;
- public bool waitForEnemys = true;
- void Start()
- {
- Spawn();
- }
- void Update()
- {
- if (waitForEnemys) return;
- if (enemy.Count == 0)
- {
- currentWave++;
- waitForEnemys = true;
- StartCoroutine(NextWave());
- }
- }
- private void Spawn()
- {
- enemy.Clear();
- int enemyCount = currentWave * 3;
- for (int i = 0; i < enemyCount; i++)
- {
- GameObject z = (GameObject)Instantiate(enemy_prefab,
- GetSpawnPoint(i, enemyCount),
- GetSpawnDirection(i));
- enemy.Add(z);
- }
- waitForEnemys = false;
- }
- private Quaternion GetSpawnDirection(int num)
- {
- return Quaternion.Euler(enemy_look - spawn_point);
- }
- private Vector3 GetSpawnPoint(int num, int max)
- {
- int q1 = (int)Mathf.Sqrt(max);
- float q2 = Mathf.Sqrt(max);
- q1 = (q1 != q2 ? q1 + 1 : q1);
- return (spawn_point +
- new Vector3(cellX * (num % q1),
- 0f,
- cellY * (num / q1)));
- }
- IEnumerator NextWave()
- {
- float time = 0;
- do
- {
- time += Time.deltaTime;
- yield return null;
- } while (time < delayBetweenWaves);
- Spawn();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement