Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- public float health; // keep the health of the enemey
- [HideInInspector]
- public Vector2 direction; // direction where the enemy is now facing.
- public GameObject bullet; // Bullet object what the enemy is gonna shoot.
- public float shootSpeed = 10; // how fast the bullet will be
- public void Shoot(Vector2 shootPosition, Vector2 direction)
- {
- // clone the bullet
- GameObject bulletObj = Instantiate(bullet, shootPosition, Quaternion.identity);
- // add force to the bullet.
- bulletObj.GetComponent<Rigidbody2D>().AddForce(direction * shootSpeed,ForceMode2D.Force);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement