using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { [SerializeField] private float speed = 4.0f; void Start() { } void Update() { transform.Translate(Vector3.down * speed * Time.deltaTime); if(transform.position.y < -5f) { float randomX = Random.Range(-8f, 8f); transform.position = new Vector3(randomX, 7, 0); } } void OnTriggerEnter2D(Collider2D other) { Debug.Log("Hit: " + other.transform.name); if(other.tag == "Player") { Player player = other.transform.GetComponent(); if(player != null ) { player.Damage(); } Destroy(this.gameObject); } if (other.tag == "Laser") { Destroy(other.gameObject); Destroy(this.gameObject); } } }