|
|
@ -1,26 +1,20 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using Unity.Netcode; |
|
|
|
using Unity.Netcode; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
using Random = UnityEngine.Random; |
|
|
|
|
|
|
|
|
|
|
|
namespace Game { |
|
|
|
namespace Game { |
|
|
|
public class Ball : NetworkBehaviour { |
|
|
|
public class Ball : NetworkBehaviour { |
|
|
|
public Rigidbody2D Rb { get; private set; } |
|
|
|
public Rigidbody2D Rb { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
private CircleCollider2D Collider { get; set; } |
|
|
|
private CircleCollider2D Collider { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public float Radius { |
|
|
|
public float Radius { |
|
|
|
get => transform.localScale.x * Collider.radius; |
|
|
|
get => transform.localScale.x * Collider.radius; |
|
|
|
set => transform.localScale = new Vector3(1, 1, 1) * value * 2; |
|
|
|
set => transform.localScale = new Vector3(1, 1, 1) * value * 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool IsAlive { |
|
|
|
public bool IsAlive { get; private set; } = true; |
|
|
|
get { |
|
|
|
|
|
|
|
float y = transform.position.y; |
|
|
|
|
|
|
|
float y1 = BorderSize.Singleton.y1; |
|
|
|
|
|
|
|
float y2 = BorderSize.Singleton.y2; |
|
|
|
|
|
|
|
return y > y1 && y < y2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable() { |
|
|
|
private void OnEnable() { |
|
|
|
Rb = GetComponent<Rigidbody2D>(); |
|
|
|
Rb = GetComponent<Rigidbody2D>(); |
|
|
|
Collider = GetComponent<CircleCollider2D>(); |
|
|
|
Collider = GetComponent<CircleCollider2D>(); |
|
|
@ -28,11 +22,14 @@ namespace Game { |
|
|
|
|
|
|
|
|
|
|
|
private void Start() { |
|
|
|
private void Start() { |
|
|
|
Rb.velocity = new Vector2(0, 25); |
|
|
|
Rb.velocity = new Vector2(0, 25); |
|
|
|
Rb.position = new Vector2(1, 0); |
|
|
|
Rb.position = new Vector2(Random.Range(-2, 2), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate() { |
|
|
|
private void FixedUpdate() { |
|
|
|
|
|
|
|
//TODO remove this and use triggers for death zone |
|
|
|
|
|
|
|
if (Rb.position.y > BorderSize.Singleton.y2 || Rb.position.y < BorderSize.Singleton.y1) { |
|
|
|
|
|
|
|
IsAlive = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|