我在具有Input.GetMouseButton(0)条件的FixedUpdate()方法中有以下代码:
public void playerAttack()
{
RaycastHit hit;
if (Physics.Raycast(player.transform.position, player.transform.forward, out hit, range)) //range = 7f
{
if (hit.rigidbody != null && hit.transform.tag == "Enemy")
{
Vector3 dir = new Vector3(hit.transform.position.x, hit.transform.position.y, hit.transform.position.z - 100f);
hit.transform.GetComponent<Rigidbody>().AddForce(dir * weaponPush * Time.deltaTime); //weaponPush = 1f
}
}
}
敌人物体上有刚体并且没有选择isKinematic。当我几乎在它前面并单击鼠标左键时,它仍然不会移动。