My game is a top-down 2D and I don’t know how to detect what direction a bullet came from and how to push the enemy back in that direction. For my gun, I did the prefab method of shooting. If anyone can help me that would be great. Thanks so much!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public int Health = 100;
public ParticleSystem PS;
public Transform enemypos;
public Rigidbody2D rb;
public void Hit(int damage){
Health -= damage;
rb.AddForce(0,0)
if(Health <= 0){
die();
}
}
void die(){
Instantiate(PS, enemypos.position, enemypos.rotation);
Destroy(gameObject);
}
}