Hello, I was instantiating a prefab by UnityOfficial tutorial for Instantiate. All work except "AddForce" command. I wrote script as in the tutorial, but variable ballPrefab I made as GameObject type instead of Rigidbody. If it is Rigidbody, I can not add prefab in the inspector into it... Here is the code:
public Transform spawner;
public GameObject ballPrefab;
void Update () {
if (Input.GetButtonDown("Fire1")) {
Rigidbody ballInstance;
ballInstance = Instantiate(ballPrefab, spawner.transform.position, spawner.rotation) as Rigidbody;
ballInstance.AddForce(spawner.forward * 3000);
}
}
↧