Skip to content

Instantly share code, notes, and snippets.

@Shubhra22
Created June 8, 2019 22:12
Show Gist options
  • Save Shubhra22/e1ed09c5a997bfbd3b17aeb4b7024c62 to your computer and use it in GitHub Desktop.
Save Shubhra22/e1ed09c5a997bfbd3b17aeb4b7024c62 to your computer and use it in GitHub Desktop.
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