Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class EnemyMove : MonoBehaviour {
  5.  
  6. // Use this for initialization
  7. public float speed;
  8. public float distance;
  9. public GameObject target;
  10. public float enemyDist;
  11. public GameObject bullet;
  12. public Transform bulletSpawner;
  13. public float timer;
  14.  
  15. void Awake(){
  16. target = GameObject.FindWithTag ("Player");
  17. }
  18.  
  19. void Update ()
  20. {
  21. timer += Time.deltaTime;
  22. distance = Vector3.Distance (target.transform.position, transform.position);
  23. transform.Translate (Vector3.left * Time.deltaTime * speed);
  24. if (distance < 60) {
  25. speed = 0;
  26. if (timer > 1) {
  27. timer = 0;
  28. Instantiate (bullet, bulletSpawner.position, bulletSpawner.rotation);
  29. }
  30.  
  31. }
  32.  
  33. }
  34. void OnCollisionEnter2D (Collision2D col)
  35. {
  36.  
  37. if (col.gameObject.tag == "Player") {
  38. Destroy (gameObject);
  39. }
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement