From 918cc4142862dbe0b7c8b2c6f9a711eca13384bb Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Thu, 13 Apr 2023 14:46:25 +0200 Subject: [PATCH] lastcontactplayer refactoring --- Assets/Scripts/Game/Ball.cs | 11 ++++++++--- Assets/Scripts/Game/Player.cs | 4 ---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/Scripts/Game/Ball.cs b/Assets/Scripts/Game/Ball.cs index 84f7a4a..187429c 100644 --- a/Assets/Scripts/Game/Ball.cs +++ b/Assets/Scripts/Game/Ball.cs @@ -6,17 +6,22 @@ using Random = UnityEngine.Random; namespace Game { public class Ball : NetworkBehaviour { + public Rigidbody2D Rb { get; private set; } + public Player LastContactPlayer { get; private set; } private CircleCollider2D Collider { get; set; } - public Player LastContactPlayer { get; set; } - public float Radius { get => transform.localScale.x * Collider.radius; set => transform.localScale = new Vector3(1, 1, 1) * value * 2; } - + + private void OnCollisionEnter2D(Collision2D other) { + if (other.gameObject.TryGetComponent(out Player player)) + LastContactPlayer = player; + } + private void Awake() { Rb = GetComponent(); Collider = GetComponent(); diff --git a/Assets/Scripts/Game/Player.cs b/Assets/Scripts/Game/Player.cs index c83f0d9..dfa7331 100644 --- a/Assets/Scripts/Game/Player.cs +++ b/Assets/Scripts/Game/Player.cs @@ -112,10 +112,6 @@ namespace Game { goingRight = false; }; } - - private void OnCollisionEnter2D(Collision2D other) { - other.gameObject.GetComponent().LastContactPlayer = this; - } } public class RealPlayer : Player {