给unity人物模型添加了碰撞组件和胶囊碰撞器,怎样添加向上的力使胶囊随人物跳动,到底哪出错了,一点反应都没有
```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColliderFollowJump : MonoBehaviour
{
public float jumpForce = 5f; // 跳跃力大小
private bool isJumping = false;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.G) && !isJumping)
{
Jump();
}
}
private void Jump()
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
isJumping = true;
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isJumping = false;
}
}
}
```