- Home /
Why won't my crate fire?
OK I'm a newbie so go easy....
I have this code that I'm using while I'm following a tutorial on Unity3d but it seems that the code they are using doesn't work in the latest version of unity or something because when I attach it to my Main camera nothing happens...
var speed = 3.0;
var cratePrefab:Transform;
function update ()
{
//when you press the button
if (Input.GetButtonDown ("Fire1"))
{
//Create Crate
var crate = Instantiate (cratePrefab, transform.position, Quaternion.identity);
//Add force to shoot it
crate.rigidbody.AddForce (transform.forward * 2000);
}
}
this is supposed to shoot cubes into the 3d world but when I left click nothing happens... Anyone want to help a newbie out?
Answer by Linus · Jul 07, 2012 at 06:42 AM
function Update ()
You need to use Update not update :)
Yes, I figured that out about an hour after I posted.... It was a noob mistake just like I suspected.
Answer by Nanity · Jul 07, 2012 at 10:23 AM
Have you ensured the rigidbody in your prefab you target can handle forces?
Means
Mass should be greater 0
"Is Kinematic" NOT ticked
"Use Gravity" NOT ticked (<- this shouldn't be the problem, but I guess you don't want bulletdrop)
Answer by eric_c · Jul 07, 2012 at 11:01 AM
var cratePrefab:Transform;
should be :
var cratePrefab : GameObject;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Free kick unity3d tutorial 1 Answer
Cannot make a world edge 3 Answers
Easy simple way to create a networking between 2 computers using bluetooth 2 Answers