-
Notifications
You must be signed in to change notification settings - Fork 0
/
BallCont.cs
65 lines (48 loc) · 1.56 KB
/
BallCont.cs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Collider))]
public class BallCont : MonoBehaviour
{
public float forceMultiplier;
private Vector3 mousePressDownPos;
private Vector3 mouseReleasePos;
private Rigidbody rb;
public bool isShoot;
private Vector3 forceV;
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
private void OnMouseDown()
{
mousePressDownPos = Input.mousePosition;
}
private void OnMouseDrag()
{
Vector3 forceInit = (Input.mousePosition - mousePressDownPos);
forceV = (new Vector3(forceInit.y, forceInit.y, z: forceInit.x)) * forceMultiplier;
Debug.Log("ForceInit x: " + forceInit.x + "||ForceInit y: " + forceInit.y + "||ForceInit z: " + forceInit.z);
Debug.Log("ForceV x: " + forceV.x + "||ForceV y: " + forceV.y + "||ForceV z: " + forceV.z);
if (!isShoot)
TrajectoryLine.Instance.GetTraj(forcevector: forceV, rb, startingPoint: transform.position);
}
private void OnMouseUp()
{
TrajectoryLine.Instance.HideLine();
mouseReleasePos = Input.mousePosition;
Shoot(Force: mousePressDownPos - mouseReleasePos);
}
void Shoot(Vector3 Force)
{
if (isShoot)
{
isShoot = false;
return;
}
rb.AddForce(new Vector3(Force.y, Force.y, z: Force.x) * forceMultiplier);
isShoot = true;
}
}