Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class EnemyMove : MonoBehaviour {
- // Use this for initialization
- public float speed;
- public float distance;
- public GameObject target;
- public float enemyDist;
- public GameObject bullet;
- public Transform bulletSpawner;
- public float timer;
- void Awake(){
- target = GameObject.FindWithTag ("Player");
- }
- void Update ()
- {
- timer += Time.deltaTime;
- distance = Vector3.Distance (target.transform.position, transform.position);
- transform.Translate (Vector3.left * Time.deltaTime * speed);
- if (distance < 60) {
- speed = 0;
- if (timer > 1) {
- timer = 0;
- Instantiate (bullet, bulletSpawner.position, bulletSpawner.rotation);
- }
- }
- }
- void OnCollisionEnter2D (Collision2D col)
- {
- if (col.gameObject.tag == "Player") {
- Destroy (gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement