using MH; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class BladeScript : ProjectileBase { [NonSerialized] public float life; private SpriteRenderer sr { get { return this.gameObject.GetComponent(); } } public void Start() { Invoke("DestroySelf", life); } void DestroySelf() { Destroy(this.gameObject); } public void Update() { Color c = sr.color; c.a *= 0.99f; sr.color = c; } public void SetFlip(bool flip) { sr.flipX = flip; } private void OnTriggerEnter2D(Collider2D other) { Debug.Log(other.gameObject.name); LayerMask layerMask = LayerMask.GetMask("Hurtbox"); if ((layerMask & (1 << other.transform.gameObject.layer)) != 0) { //Debug.Log(other.GetType().Name); Rigidbody2D rig = other.transform.parent.GetComponent(); if(rig != null) { Debug.Log("force"); UnitBase hero = UnitManager.hero; Vector2 pos = transform.position; Vector2 heroPos = hero.transform.position; Vector2 dir = (heroPos - pos).normalized; rig.AddForce(-dir * 100); rig.GetComponent().Die(); } } } }