Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Enemy : MonoBehaviour
  4. {
  5. public float health; // keep the health of the enemey
  6.  
  7. [HideInInspector]
  8. public Vector2 direction; // direction where the enemy is now facing.
  9.  
  10. public GameObject bullet; // Bullet object what the enemy is gonna shoot.
  11.  
  12. public float shootSpeed = 10; // how fast the bullet will be
  13.  
  14.  
  15. public void Shoot(Vector2 shootPosition, Vector2 direction)
  16. {
  17. // clone the bullet
  18. GameObject bulletObj = Instantiate(bullet, shootPosition, Quaternion.identity);
  19.  
  20. // add force to the bullet.
  21. bulletObj.GetComponent<Rigidbody2D>().AddForce(direction * shootSpeed,ForceMode2D.Force);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement