Newer
Older
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
66
67
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ForceBarController : MonoBehaviour
{
private Image bar;
[SerializeField] private Image backgroundBar;
[SerializeField] private GameObject player;
private bool isDumping;
private bool shotAttemped;
private bool canShoot;
private float force;
private Rigidbody2D playerRb;
private Animator playerAnimator;
private void Start()
{
bar = GetComponent<Image>();
backgroundBar.fillAmount = 0;
canShoot = true;
playerRb = player.GetComponent<Rigidbody2D>();
playerAnimator = player.GetComponent<Animator>();
}
private void FixedUpdate()
{
if (playerRb.velocity == Vector2.zero)
{
if (shotAttemped && Input.GetAxis("Shot") == 0)
{
force = bar.fillAmount;
shotAttemped = false;
isDumping = false;
FindObjectOfType<TestScript>().shoot(force);
bar.fillAmount = 0;
backgroundBar.fillAmount = 0;
playerAnimator.SetBool("Shooting", false);
}
if (Input.GetAxis("Shot") != 0)
{
playerAnimator.SetBool("Shooting", true);
backgroundBar.fillAmount = 1;
if (bar.fillAmount < 1 && !isDumping)
{
bar.fillAmount += Time.deltaTime;
}
else if (bar.fillAmount == 1)
{
//perfect
isDumping = true;
}
if (isDumping)
{
bar.fillAmount -= Time.deltaTime;
}
shotAttemped = true;
}
}
}
private void updateState()
{
canShoot = canShoot == true ? false : true;
}
}