UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"throw a baseball ball"
/* player throws a baseball ball on mouse click */ public class BaseballThrow : MonoBehaviour { public GameObject baseballPrefab; public Transform throwPosition; public float throwForce = 10f; void Update() { if (Input.GetMouseButtonDown(0)) { ThrowBaseball(); } } void ThrowBaseball() { GameObject baseball = Instantiate(baseballPrefab, throwPosition.position, throwPosition.rotation); Rigidbody rb = baseball.GetComponent<Rigidbody>(); rb.AddForce(throwPosition.forward * throwForce, ForceMode.Impulse); } }