using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class Ball : MonoBehaviour
{
    [Header(" Physics Settings ")]
    [SerializeField] private float bounceVelocity;
    private Rigidbody2D rig;
    void Start()
    {
        rig = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        
    }
    private void Bounce(Vector2 normal) {
        rig.velocity = normal * bounceVelocity;
    }
    private void OnCollisionEnter2D(Collision2D collision) {
        if(collision.collider.TryGetComponent(out PlayerControler pc)) {
            Bounce(collision.GetContact(0).normal);
        }
    }
}
