update lại về cam và logic
This commit is contained in:
32
Assets/Script/BouncyBall.cs
Normal file
32
Assets/Script/BouncyBall.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BouncyBall : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
// Tự động gán Tag để chắc chắn ScoreManager nhận ra quả bóng
|
||||
gameObject.tag = "Ball";
|
||||
|
||||
Rigidbody rb = GetComponent<Rigidbody>();
|
||||
if (rb != null)
|
||||
{
|
||||
// Đảm bảo quả bóng có trọng lượng và không quá nặng
|
||||
rb.mass = 0.6f; // Khối lượng chuẩn quả bóng rổ (kg)
|
||||
rb.collisionDetectionMode = CollisionDetectionMode.Continuous;
|
||||
}
|
||||
|
||||
Collider col = GetComponent<Collider>();
|
||||
if (col != null)
|
||||
{
|
||||
// Tạo Physic Material bằng code nếu chưa có
|
||||
PhysicsMaterial bouncyMat = new PhysicsMaterial("BasketballMaterial");
|
||||
bouncyMat.bounciness = 0.8f; // Độ nảy (0 đến 1)
|
||||
bouncyMat.bounceCombine = PhysicsMaterialCombine.Maximum;
|
||||
bouncyMat.frictionCombine = PhysicsMaterialCombine.Minimum;
|
||||
bouncyMat.staticFriction = 0.4f;
|
||||
bouncyMat.dynamicFriction = 0.4f;
|
||||
|
||||
col.material = bouncyMat;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user