]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Controllers/Ball.cs
Add non working time shooting
[gmtk-gamejam.git] / Assets / Scripts / Controllers / Ball.cs
1 using System;
2 using System.Net.Mime;
3 using UnityEngine;
4
5 namespace Controllers
6 {
7 [RequireComponent(typeof(Rigidbody2D))]
8 [RequireComponent(typeof(CircleCollider2D))]
9 public class Ball : MonoBehaviour
10 {
11 internal GameController controller;
12
13 [SerializeField] private float shotForce;
14
15 public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
16 private Rigidbody2D _rigidbody;
17
18 private void OnCollisionEnter2D(Collision2D other)
19 {
20 controller.BallDropped();
21 }
22
23 public void Shoot(Vector3 target, float time)
24 {
25 transform.right = target - transform.position;
26 Rigidbody.velocity = Vector2.zero;
27 Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * (shotForce * ((Mathf.Clamp(time, 0f, 1f) + 1))));
28 }
29 }
30 }