Advertisement
crystalguy123

Untitled

Jan 24th, 2020
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Enemy : MonoBehaviour
  6. {
  7. [SerializeField]
  8. private float _speed = 4.0f;
  9.  
  10.  
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14.  
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update()
  19. {
  20. //move down at 4 m/s
  21. transform.Translate(Vector3.down * Time.deltaTime * _speed);
  22.  
  23.  
  24. //if bottom of screen reset at top
  25. if (transform.position.y < -5f)
  26. {
  27. float randomX = Random.Range(-8f, 8f);
  28. transform.position = new Vector3(randomX, 7, 0);
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. }
  37.  
  38. private void OnTriggerEnter(Collider other)
  39. {
  40. if (other.tag == "Player")
  41. {
  42. Destroy(this.gameObject);
  43. }
  44.  
  45. if (other.tag == "Lazer")
  46. {
  47. Destroy(other.gameObject);
  48. Destroy(this.gameObject);
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement