using UnityEngine;
using System.Collections;
public class EnemySpawner01 : MonoBehaviour {
public GameObject Enemy;
public GameObject propInstance;
void Start ()
{
propInstance = (GameObject)Instantiate(Enemy, transform.position, Quaternion.identity);
// Set the prop's velocity to this speed in the x axis.
}
void Update ()
{
if(propInstance) {
if(propInstance.transform.position.y < - 12.0f)
// ... destroy the prop.
Destroy(propInstance);
}
}
}
using UnityEngine;
using System.Collections;
public class EnemySpawner02 : MonoBehaviour {
public GameObject Enemy;
public float leftSpwanPosX;
public float rightSpwanPosX;
public float PosY;
public float minTimeBetweenSpawns;
public float maxTimeBetweenSpawns;
public GameObject propInstance;
// Use this for initialization
void Start () {
Random.seed = System.DateTime.Today.Millisecond;
StartCoroutine ("createEnemy");
}
IEnumerator createEnemy() {
float waitTime = Random.Range (minTimeBetweenSpawns, maxTimeBetweenSpawns);
yield return new WaitForSeconds (waitTime);
float posX = Random.Range (leftSpwanPosX, rightSpwanPosX);
Vector3 enemyPos = new Vector3 (posX, PosY, transform.position.z);
propInstance = (GameObject)Instantiate (Enemy, enemyPos, Quaternion.identity);
StartCoroutine (createEnemy ());
}
}
using UnityEngine;
using System.Collections;
public class EnemyPattern0101 : MonoBehaviour {
public Transform playerPosition;
public float minSpeed = 2.0f;
public float maxSpeed = 3.0f;
void Start() {
playerPosition = GameObject.Find ("Hero").GetComponent<Transform>();
Vector3 temp = Vector3.Normalize(playerPosition.position - transform.position);
Debug.Log ("temp :" + temp.y);
float speed = Random.Range (minSpeed, maxSpeed);
rigidbody2D.velocity = new Vector2 (temp.x*speed, temp.y*speed);
}
void Update() {
}
}
using UnityEngine;
using System.Collections;
public class ShootEveryTimeStep : MonoBehaviour {
public GameObject Missile;
public Transform shotSpawn;
public float TimeStep = 0.2f;
private float DeltaTime = 0;
void Start () {
}
// Update is called once per frame
void Update () {
DeltaTime += Time.deltaTime;
if(DeltaTime > TimeStep) {
DeltaTime -= TimeStep;
Instantiate(Missile, shotSpawn.position, Quaternion.identity);
}
}
}
using UnityEngine;
using System.Collections;
public class EnemiesCollision : MonoBehaviour {
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "HeroMissile") {
Debug.Log ("HeroMissile");
Destroy(gameObject);
Destroy (other.gameObject);
}
}
}
using UnityEngine;
using System.Collections;
public class HeroesCollision01 : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D (Collider2D other)
{
if((other.tag == "EnemyMissile")|| (other.tag == "Enemy")) {
Destroy(gameObject);
Destroy (other.gameObject);
}
}
}
using UnityEngine;
using System.Collections;
public class EnemyPattern0102 : MonoBehaviour {
public Transform playerPosition;
public float minSpeed = 2.0f;
public float maxSpeed = 3.0f;
void Start() {
GameObject tempObj = GameObject.Find ("Hero");
if (!tempObj)
return;
playerPosition = tempObj.GetComponent<Transform>();
//playerPosition = GameObject.Find ("Hero").GetComponent<Transform>();
Vector3 temp = Vector3.Normalize(playerPosition.position - transform.position);
//Debug.Log ("temp :" + temp.y);
float speed = Random.Range (minSpeed, maxSpeed);
rigidbody2D.velocity = new Vector2 (temp.x*speed, temp.y*speed);
}
void Update() {
}
}
using UnityEngine;
using System.Collections;
public class EnemyPattern02 : MonoBehaviour {
public float maxSpeed = 3.0f;
public float minSpeed = 1.0f;
private float speed = 0.0f;
private bool bLeft = false;
// Use this for initialization
void Start () {
speed = Random.Range (minSpeed, maxSpeed);
rigidbody2D.velocity = new Vector2 (speed, 0);
}
// Update is called once per frame
void Update () {
if ((transform.position.x > 2) && !bLeft) {
speed = speed * -1;
rigidbody2D.velocity = new Vector2 (speed, 0);
bLeft = true;
} else if((transform.position.x < -2) && bLeft) {
speed = speed * -1;
rigidbody2D.velocity = new Vector2 (speed, 0);
bLeft = false;
}
}
}