- Home /
Question by
JulianRen · Mar 08 at 10:18 AM ·
addforceontriggerenter
How to make a game object been shoot, on mouse button been clicked, as it enters an area ,How to make a game object enters an area be shoot as on mouse been clicked
Hello,
all I'm currently working on shooting the game object as it enters an area, and as it enters the area, if the mouse been clicked, that game object would be shot, how to achieve that?
public class shoot : MonoBehaviour
{
[SerializeField] float speed = 10f;
void OnTriggerEnter ( Collider other )
{
if (other.gameObject.CompareTag("ball"))
{
Debug.Log("ball detected");
if (Input.GetMouseButtonDown(0))
{
Debug.Log("shoot!");
other.gameObject.GetComponent<Rigidbody>().AddForce(transform.forward * speed, ForceMode.Impulse);
}
}
}
}
Thanks!
Comment
Your answer

Follow this Question
Related Questions
OnTriggerEnter AddForce 1 Answer
OnTriggerEnter AddForce OK??? 1 Answer
How to disable constant force over time? Rocket game 2 Answers
Adding Force to a Rigidbody through OnTriggerEnter 1 Answer
Increase Speed 1 Answer