Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- [SerializeField]
- private float _speed = 4.0f;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- //move down at 4 m/s
- transform.Translate(Vector3.down * Time.deltaTime * _speed);
- //if bottom of screen reset at top
- if (transform.position.y < -5f)
- {
- float randomX = Random.Range(-8f, 8f);
- transform.position = new Vector3(randomX, 7, 0);
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag == "Player")
- {
- Player player = other.transform.GetComponent<Player>();
- if (player != null)
- {
- player.Damage();
- }
- Destroy(this.gameObject);
- }
- if (other.tag == "Lazer")
- {
- Destroy(other.gameObject);
- Destroy(this.gameObject);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement