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.
40 lines
974 B
40 lines
974 B
using System;
|
|
using System.Collections;
|
|
using Unity.Netcode;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace Game {
|
|
public class Ball : NetworkBehaviour {
|
|
|
|
public Rigidbody2D Rb { get; private set; }
|
|
public Player LastContactPlayer { get; private set; }
|
|
public bool IsPermanent { get; set; }
|
|
|
|
private CircleCollider2D Collider { get; set; }
|
|
|
|
private const float SpeedGain = 1.025f;
|
|
|
|
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))
|
|
PlayerContact(player);
|
|
}
|
|
|
|
private void PlayerContact(Player player) {
|
|
LastContactPlayer = player;
|
|
Rb.velocity *= SpeedGain;
|
|
}
|
|
|
|
private void Awake() {
|
|
Rb = GetComponent<Rigidbody2D>();
|
|
Collider = GetComponent<CircleCollider2D>();
|
|
}
|
|
|
|
}
|
|
}
|
|
|