You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
902 B

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