void DoCollisionStuff(Collider2D collision) { if (collision.gameObject.tag.Contains("Player,")) { //Debug.Log("ALERT"); switch (parenType) { case "RedGolem": switch (rGolemScript.GetState()) { case "findNextState": if (rGolemScript.GetStateLock() > 0) { break; } else { rGolemScript.SetTargetObject(collision.gameObject); rGolemScript.SetState("pursuit"); rGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "idle": if (rGolemScript.GetStateLock() > 0) { break; } else { rGolemScript.SetTargetObject(collision.gameObject); rGolemScript.SetState("pursuit"); rGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "stroll": rGolemScript.SetTargetObject(collision.gameObject); rGolemScript.SetState("pursuit"); rGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; break; case "flee": if (rGolemScript.GetStateLock() > 0) { break; } else { rGolemScript.SetTargetObject(collision.gameObject); rGolemScript.SetState("pursuit"); rGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "pursuit": if (rGolemScript.GetStateLock() == 0f) { rGolemScript.SetState("attack"); rGolemScript.SetXVelocity(0f); rGolemScript.EnterPhysicsMode(); } break; } break; case "GreenGolem": switch (gGolemScript.GetState()) { case "findNextState": if (gGolemScript.GetStateLock() > 0) { break; } else { gGolemScript.SetTargetObject(collision.gameObject); gGolemScript.SetState("pursuit"); gGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "idle": if (gGolemScript.GetStateLock() > 0) { break; } else { gGolemScript.SetTargetObject(collision.gameObject); gGolemScript.SetState("pursuit"); gGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "stroll": if (gGolemScript.GetStateLock() > 0) { break; } else { gGolemScript.SetTargetObject(collision.gameObject); gGolemScript.SetState("pursuit"); gGolemScript.SetStateLock(.05f); range.size = attackRange; range.offset = attackOffset; } break; case "pursuit": if (gGolemScript.GetStateLock() == 0f) { gGolemScript.SetState("attack"); gGolemScript.SetXVelocity(0f); gGolemScript.EnterPhysicsMode(); } break; } break; } } else { } //Debug.Log(range.size); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.GetComponent <Rigidbody2D>() != null) { if (!collision.gameObject.tag.Contains(alignment + ",")) { if (autoCalckb) { knockBackAngle = Vector2.Angle(new Vector2(transform.position.x, transform.position.y), new Vector2(collision.transform.position.x, collision.transform.position.y)); } target = collision.gameObject; if (target.tag.Contains("Player,")) { playerScript = target.GetComponent <PlayerController>(); playerScript.Hp -= damage; playerScript.HurtPlayer(); playerScript.IncomingKb = new Vector2(knockback, 0).Rotate(knockBackAngle); playerScript.Invoke("ApplyKb", 0.01f); GameObject particles = Instantiate(playerScript.hurtParticles); particles.transform.position = playerScript.transform.position; particles.transform.localScale = new Vector3(particles.transform.localScale.x * playerScript.GetDir(), particles.transform.localScale.y, particles.transform.localScale.z); } else if (target.tag.Contains("Prop,")) { propScript = target.GetComponent <PropController>(); propScript.hp -= damage; } else if (target.tag.Contains("RedGolem,")) { rGolemScript = collision.gameObject.GetComponent <RedGolemController>(); rGolemScript.hp -= damage; rGolemScript.SetHitStun(); rGolemScript.SetTargetObject(transform.parent.gameObject); rGolemScript.IncomingKb = new Vector2(knockback, 0).Rotate(knockBackAngle); rGolemScript.Invoke("ApplyKb", 0.01f); GameObject particles = Instantiate(rGolemScript.hurtParticles); particles.transform.position = rGolemScript.transform.position; particles.transform.localScale = new Vector3(particles.transform.localScale.x * rGolemScript.GetDir(), particles.transform.localScale.y, particles.transform.localScale.z); } else if (target.tag.Contains("GreenGolem,")) { gGolemScript = collision.gameObject.GetComponent <GreenGolemController>(); gGolemScript.hp -= damage; gGolemScript.SetHitStun(); gGolemScript.SetTargetObject(transform.parent.gameObject); gGolemScript.IncomingKb = new Vector2(knockback, 0).Rotate(knockBackAngle); gGolemScript.Invoke("ApplyKb", 0.01f); GameObject particles = Instantiate(gGolemScript.hurtParticles); particles.transform.position = gGolemScript.transform.position; particles.transform.localScale = new Vector3(particles.transform.localScale.x * gGolemScript.GetDir(), particles.transform.localScale.y, particles.transform.localScale.z); } /* * -------------Template for What the added force is--------------------- * #use invoke to put a small delay to avoid bugs that involve controller and damage script running simutaneously * otherRigid.AddForce(new Vector2(knockback, 0).Rotate(knockBackAngle), ForceMode2D.Impulse); * */ Physics2D.IgnoreCollision(range, collision); } } }