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 FlyingEnemy : MonoBehaviour
- {
- public float flyHealth = 1;
- private float spearDamage = 1;
- private float leftMove = 2.0f;
- private float rightMove = 2.0f;
- private float speed = 5.0f;
- private int direction = 1;
- private Vector2 movement;
- public Rigidbody potion;
- public GameObject otherEnemy;
- // Update is called once per frame
- void Update()
- {
- while (flyHealth == 1)
- {
- if (transform.position.x > rightMove)
- {
- direction = -1;
- }
- else if (transform.position.x > leftMove)
- {
- direction = 1;
- }
- movement = Vector2.right * direction * speed * Time.deltaTime;
- transform.Translate(movement);
- if (Random.Range(0f, 1f) == 1)
- {
- Rigidbody potionInstance;
- potionInstance = Instantiate(potion) as Rigidbody;
- potionInstance.AddForce(Vector3.down * 5000);
- }
- }
- }
- private void OnTriggerEnter2D(Collider2D other)
- {
- if (other.tag == "Spear")
- {
- flyHealth -= spearDamage;
- }
- if (flyHealth <= 0)
- {
- Destroy(otherFlyEnemy);
- if (Random.Range(0f, 1f) == 1)
- {
- Rigidbody potionInstance;
- potionInstance = Instatiate(potion) as Rigidbody;
- potionInstance.addForce(Vector3.down * 5000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement