You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
984 B
46 lines
984 B
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<Player>(); |
|
if(player != null ) |
|
{ |
|
player.Damage(); |
|
} |
|
Destroy(this.gameObject); |
|
} |
|
|
|
if (other.tag == "Laser") |
|
{ |
|
Destroy(other.gameObject); |
|
Destroy(this.gameObject); |
|
} |
|
} |
|
}
|
|
|