blob: 07e1b37f50fc99c3d5cd70de5cf023ab53826948 (
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
29
30
|
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;
public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent<Rigidbody2D>();
private Rigidbody2D _rigidbody;
private void OnCollisionEnter2D(Collision2D other)
{
controller.BallDropped();
}
public void Shoot(Vector3 target)
{
transform.right = target - transform.position;
Rigidbody.velocity = Vector2.zero;
Rigidbody.AddForce((transform.right + (transform.up * 0.5f)) * shotForce);
}
}
}
|