private void OnTriggerStay2D(Collider2D other) { var gameObject = other.gameObject; if (gameObject == Target) { var entity = gameObject.GetComponent <Entity>(); if (entity != null) { healthModifier.Health = entity.GetCapability <Health>(); } animatorTrigger.Animator = gameObject.transform.GetChild(0).GetComponent <Animator>(); animatorTrigger.Name = "Hit"; if (other.gameObject.GetComponent <Entity>().GetCapability <Health>().Value < 0) { animatorTrigger.Name = "Die"; if (other.gameObject.CompareTag("Player")) { StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(0f); stopPlayerMovementFragment.TakeEffect(other.GetComponent <Entity>()); StopPlayerStateFragment stopPlayerStateFragment = new StopPlayerStateFragment(0f); stopPlayerStateFragment.TakeEffect(other.GetComponent <Entity>()); } ; gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; } creatEffectModifier.HitPoint = transform; TakeEffect(); ObjectPool.RecycleObject(this.gameObject); } }
private IEnumerator SweepCorotinue() { WaitForFixedUpdate wait = new WaitForFixedUpdate(); float timer = time; float anglePerFrame = angle / time * Time.fixedDeltaTime; float halfAngle = angle / 2; transform.Rotate(0, 0, -halfAngle); while (timer > 0) { var hits = Physics2D.RaycastAll(transform.position, transform.right); foreach (var hit in hits) { var gameObject = hit.transform.gameObject; if (gameObject == Target) { var entity = gameObject.GetComponent <Entity>(); if (entity != null) { healthModifier.Health = entity.GetCapability <Health>(); } animatorTrigger.Animator = gameObject.GetComponent <Animator>(); animatorTrigger.Animator = gameObject.transform.GetChild(0).GetComponent <Animator>(); animatorTrigger.Name = "Hit"; if (gameObject.GetComponent <Entity>().GetCapability <Health>().Value <= 0) { animatorTrigger.Name = "Die"; if (gameObject.gameObject.CompareTag("Player")) { StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(0f); stopPlayerMovementFragment.TakeEffect(gameObject.GetComponent <Entity>()); StopPlayerStateFragment stopPlayerStateFragment = new StopPlayerStateFragment(0f); stopPlayerStateFragment.TakeEffect(gameObject.GetComponent <Entity>()); } ; gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; } TakeEffect(); timer = 0; } } timer -= Time.fixedDeltaTime; transform.Rotate(0, 0, anglePerFrame); yield return(wait); } ObjectPool.RecycleObject(gameObject); }
public override void HitRecycleNow() { transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); if (IsNotRecycled) { if (HitEffect != null || HitEffect != "") { GameObject shootHitEffect = ObjectPool.GetObject(HitEffect, "Effects"); shootHitEffect.transform.position = transform.position + Vector3.forward * 10f; } Nowtime = 0; List <GameObject> targets = GetAttackTargets(); if (targets != null && targets.Count != 0) { foreach (var t in targets) { gravitationModifier = new GravitationModifier(transform.position, GravitationInternal, GravitationPower); gravitationModifier.TakeEffect(t.GetComponent <Entity>()); AnimatorParameterFragment animator = new AnimatorParameterFragment(); for (int i = 0; i < 3; i++) { HealthModifier hm = new HealthModifier(-30); hm.TakeEffect(t.GetComponent <Entity>()); animator.Animator = t.transform.GetChild(0).GetComponent <Animator>(); animator.Name = "Hit"; animator.TakeEffect(); } if (t.gameObject.GetComponent <Entity>().GetCapability <Health>().Value < 0) { animator.Name = "Die"; animator.TakeEffect(); if (t.gameObject.CompareTag("Player")) { StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(0f); stopPlayerMovementFragment.TakeEffect(t.GetComponent <Entity>()); StopPlayerStateFragment stopPlayerStateFragment = new StopPlayerStateFragment(0f); stopPlayerStateFragment.TakeEffect(t.GetComponent <Entity>()); } ; gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; } } } flyingDistance = 0; targetDistance = 0; ObjectPool.RecycleObject(gameObject); IsNotRecycled = false; } }