aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Assets/Scripts/Controllers/Ball.cs
blob: 45e607b53277322f39829822c2a2121c4cc2f24f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Net.Mime;
using UnityEngine;

namespace Controllers
{
  [RequireComponent(typeof(Rigidbody2D))]
  [RequireComponent(typeof(CircleCollider2D))]
  public class Ball : MonoBehaviour
  {
    internal GameController controller;

    [SerializeField] private float shotForce;
    
    private void OnCollisionEnter2D(Collision2D other)
    {
      controller.BallDropped();
    }

    public void Shoot(Vector3 target)
    {
      transform.right = (target - transform.position);
      var rb = GetComponent<Rigidbody2D>();
      rb.velocity = Vector2.zero;
      rb.AddForce((transform.right + (transform.up * 0.5f)) * shotForce);
    }
  }
}