void OnCollisionEnter2D(Collision2D CollisionInfo) { GameObject OtherObj = CollisionInfo.collider.gameObject; if (OtherObj != Owner) { if (OtherObj.tag == "Player") { GPlayer PlayerScript = OtherObj.GetComponent <GPlayer>(); FPlayerInfo PlayerInfo = PlayerScript.GetPlayerInfo(); float TotalDamage = PlayerInfo.Health * 0.65f; FDamageInfo DamageInfo = new FDamageInfo(); DamageInfo.DamageDone = TotalDamage; PlayerScript.SendMessage("TakeDamage", DamageInfo); Destroy(this.gameObject); } else if (OtherObj.tag == "Environment") { //TODO::Splash damage Destroy(this.gameObject); } } }
public void Attack(float DamageAmt) { // Raycast Vector3 RayStartPos = transform.position; RayStartPos.x += (bFacingRight) ? (PlayerTextureWidth / 2) + 0.25f : -((PlayerTextureWidth / 2) + 0.25f); RaycastHit2D Hit2D = Physics2D.Raycast(RayStartPos, (bFacingRight) ? Vector2.right * 10 : Vector2.right * -10); if (Hit2D && Hit2D.collider) { if (Hit2D.distance <= MaxAttackDistance) { // If we've found a player, call take damage for the attack amount. FPlayerInfo PlayerInfo = PlayerScript.GetPlayerInfo(); GameObject HitObject = Hit2D.collider.gameObject; float TotalDamage = DamageAmt * (1 - (PlayerInfo.Fatigue / 100.0f)); HitObject.SendMessage("TakeDamage", TotalDamage); } } }