22 lines
848 B
C#
22 lines
848 B
C#
using UnityEngine;
|
|
|
|
public class BallShooter : MonoBehaviour
|
|
{
|
|
public GameObject ballPrefab; // Kéo prefab quả bóng vào đây
|
|
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
|
|
|
|
// Gọi hàm này khi bấm nút Ném trên UI
|
|
public void ShootBall()
|
|
{
|
|
GameObject newBall = Instantiate(ballPrefab, shootPoint.position, shootPoint.rotation);
|
|
Rigidbody rb = newBall.GetComponent<Rigidbody>();
|
|
|
|
// Thêm lực để quả bóng bay về phía trước và hơi hếch lên trên
|
|
rb.AddForce(shootPoint.forward * shootForce + Vector3.up * upwardForce);
|
|
|
|
// Hủy quả bóng sau 5 giây để tránh lag game
|
|
Destroy(newBall, 5f);
|
|
}
|
|
} |