Hi all, I followed a lot of tutorial but none resolved my problem. I want to shoot an arrow. I made a spawnPoint empty gameObject, I made my arrow prefab with a cube on wich I added a rigidbody and I linked this script to my spawnPoint…
using UnityEngine;
using System.Collections;
public class prefabShooting : MonoBehaviour {
public Rigidbody projectilePrefab;
public int projectileSpeed;
public void Update(){
if(Input.GetKey("f")){
Rigidbody instantiatedProjectile;
projectileSpeed=10;
instantiatedProjectile=Instantiate(projectilePrefab, transform.position, transform.rotation) as Rigidbody;
instantiatedProjectile.velocity=transform.TransformDirection (new Vector3(0,0,projectileSpeed));
//Destroy(clone.gameObject, 5);
}
}
}
I press play and the game start but when I press F the game pause and send me this error…
UnassignedReferenceException: The variable projectilePrefab of prefabShooting has not been assigned.
You probably need to assign the projectilePrefab variable of the prefabShooting script in the inspector.
but I affected it. When I unpause the game, an arrow appear and is shot like supposed too
but when I press F again the game pause again and the process start over again and again indefinitely until I stop it… Can somebody help me here before I turn crazy.