using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RedSword : MonoBehaviour {
public float knockback;
public Rigidbody2D rbOfEnemy;
public string nameOfEnemy;
public GameObject gO;
//Knockback direction
public Vector2 kbdir;
void Start () {
}
void Update ()
{
}
private void OnCollisionEnter2D(Collision2D collision)
{
nameOfEnemy = collision.collider.name;
gO = GameObject.Find(nameOfEnemy);
gO.GetComponent<Rigidbody2D>();
rbOfEnemy = gO.GetComponent<Rigidbody2D>();
if (collision.collider.tag == "Enemy" )
{
applyKnockback();
}
}
private void applyKnockback()
{ //I want to find out which direction the object is moving based on the rigidbody (kbdir)
rbOfEnemy.AddForce(kbdir * knockback * Time.deltaTime);
Invoke("removeKnockback", .001f);
}
private void removeKnockback()
{
//How do I stop force
}
}