Advertisement
crystalguy123

Untitled

Jan 24th, 2020
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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. Player player = other.transform.GetComponent<Player>();
  43.  
  44. if (player != null)
  45. {
  46. player.Damage();
  47. }
  48.  
  49. Destroy(this.gameObject);
  50. }
  51.  
  52. if (other.tag == "Lazer")
  53. {
  54. Destroy(other.gameObject);
  55. Destroy(this.gameObject);
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement