Created
June 8, 2019 22:12
-
-
Save Shubhra22/e1ed09c5a997bfbd3b17aeb4b7024c62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment