Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Enemy : MonoBehaviour {
- public Transform TS;
- public float minSpeed = 3f, maxSpeed = 8f, currentSpeed;
- public float llocation = -9.15f, rlocation = 9.15f, ylocation = 7.65f;
- // Use this for initialization
- void Start () {
- TS = transform; //Cache Transform.
- currentSpeed = Random.Range(minSpeed, maxSpeed); //Randomize enemy speed;
- TS.position = new Vector3 (Random.Range (llocation, rlocation), ylocation, 0); //Randomize enemy spawn point.
- }
- // Update is called once per frame
- void Update () {
- TS.position += (Vector3.down * currentSpeed * Time.deltaTime); //Bring enemy down the screen.
- if (TS.position.y < -5.35f) {
- TS.position = new Vector3 (Random.Range (llocation, rlocation), ylocation, 0);
- currentSpeed = Random.Range(minSpeed, maxSpeed);
- } //end new spawnpoint and speed.
- }
- void OnTriggerEnter(Collider collider)
- {
- if (collider.CompareTag("Laser") || collider.CompareTag("Player")) { //Tag is name of prefab.
- //When the laser hits the enemy, destroy the laser and the enemy.
- Destroy(this.gameObject);
- }
- if (Player.score < 500 || Player.playerLives >= 1) {
- for (int enemies = 0; enemies < 3; enemies++) {
- Vector3 nposition = new Vector3 (Random.Range (llocation, rlocation), ylocation, 0);
- Instantiate(this, nposition, Quaternion.identity);
- TS.position += (Vector3.down * currentSpeed * Time.deltaTime);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement