Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- public class KnockBack : MonoBehaviour
- {
- public Rigidbody2D theRB;
- public float thrust;
- public float knockTime;
- public string otherTag;
- private void OnTriggerEnter2D(Collider2D other)
- {
- if(other.gameObject.CompareTag("Enemy") && other.isTrigger)
- {
- Rigidbody2D hit = other.GetComponentInParent<Rigidbody2D>();
- if (hit != null)
- {
- // hit.AddForce(difference, ForceMode2D.Impulse);
- if (other.gameObject.CompareTag(otherTag) && other.isTrigger)
- {
- hit.GetComponent<EnemyController>().currentState = EnemyStates.stagger;
- other.GetComponent<EnemyController>().Knock(hit, knockTime);
- }
- if (other.GetComponent<PlayerController>().state != PlayerState.stagger)
- {
- hit.GetComponent<PlayerController>().state = PlayerState.stagger;
- Knock(knockTime);
- }
- }
- }
- }
- public void Knock(float knocktime)
- {
- StartCoroutine(Knockco(knocktime));
- }
- private IEnumerator Knockco(float knockTime)
- {
- if (theRB != null)
- {
- yield return new WaitForSeconds(knockTime);
- theRB.velocity = Vector2.zero;
- theRB.velocity = Vector2.zero;
- }
- }
- }
Add Comment
Please, Sign In to add comment