update time , score

This commit is contained in:
2026-05-11 21:35:39 +07:00
parent 8bf28a39fa
commit 685b3b6e12
6 changed files with 167 additions and 36 deletions

View File

@@ -6,9 +6,23 @@ public class BallShooter : MonoBehaviour
public Transform shootPoint; // Kéo điểm ShootPoint vào đây
public float shootForce = 500f;
public float upwardForce = 200f; // Lực ném vòng cung lên trên
[Header("Shooting Limit")]
public float shootCooldown = 2f; // Thời gian chờ giữa 2 lần ném
private float nextShootTime = 0f;
public void ShootBall()
{
// Kiểm tra xem đã đến lúc được ném chưa
if (Time.time < nextShootTime)
{
Debug.Log($"<color=yellow>Chờ một chút! Cần {(nextShootTime - Time.time):F1}s nữa để ném tiếp.</color>");
return;
}
// Cập nhật thời gian ném tiếp theo
nextShootTime = Time.time + shootCooldown;
// 1. Lấy vị trí ném: Từ Camera lùi xuống dưới một chút (giống tay người cầm bóng)
Vector3 spawnPosition = Camera.main.transform.position
+ Camera.main.transform.forward * 0.5f
@@ -20,6 +34,13 @@ public class BallShooter : MonoBehaviour
// 3. Đảm bảo bóng không bị dính vào Image Target
newBall.transform.SetParent(null);
// Gán vị trí ném vào script BouncyBall
BouncyBall ballScript = newBall.GetComponent<BouncyBall>();
if (ballScript != null)
{
ballScript.shotPosition = Camera.main.transform.position;
}
Rigidbody rb = newBall.GetComponent<Rigidbody>();
if (rb != null)
{