- Home /
Gun Shooting bug
Hi,
I'm new to scripting and Unity and I'm trying to make a gun shoot. I have the gun, the bullet model, the bulletspawn and the scripts. But there is something wrong with the GunShoot script and the BulletSpeed script.
Here is my Gun Shoot script:
var BulletSpawn : Transform;
var Bullet : GameObject;
function Start () {
}
function Update () {
if (Input.GetButtonDown ("Fire1"))(
Instantiate(Bullet ,BulletSpawn.transform.position , BulletSpawn.transform.rotation));
}
Here is the script that I use to set the speed of the bullet:
var BulletSpeed = 5;
function Start () {
}
function Update () {
Transform.UnityEngine.Translate(Vector3.Forward * Time.deltaTime * BulletSpeed);
}
Saying "there is something wrong" does not tell us anything. You need to describe what you want it to do and what its doing. Right now I can tell you that the bullet script will not compile. There is no such thing as 'Vector3.Forward' with an upper case 'F'. It should be Vector3.forward.
@robertbu I don't understand how people don't see the giant error warnings when they try to play with broken scripts. Worst part is: "There's a thing giving me information I don't understand. Lets leave all that information out when we ask people about this problem"...
a good reason not to start leaning program$$anonymous$$g in a very feature-full development environment :)
Answer by vinod.kapoor · Jul 16, 2013 at 11:57 AM
//first script code
var BulletSpawn : Transform; var Bullet : GameObject;
function Start () {
}
function Update () {
if (Input.GetButtonDown ("Fire1")){
var bullt : GameObject = Instantiate(Bullet ,BulletSpawn.transform.position , BulletSpawn.transform.rotation) ;
}
}
// second script code
var BulletSpeed = 5;
function Start () {
}
function Update () {
transform.Translate(Vector3.forward * Time.deltaTime * BulletSpeed);
}
Please fix the code in your answer. Also, would you $$anonymous$$d explaining what you changed / improved? This will help people who see this in the future.
in his second script, he has written
Transform.UnityEngine.Translate(Vector3.Forward * Time.deltaTime * BulletSpeed);
Transform(with capital T)represent class and transform(with small T) represent the object of this class. so we nee to use transform(with small T) ins$$anonymous$$d of Transform. another thing is There is nothing like Vector3.Forward(capital F in forward). ins$$anonymous$$d it is Vector3.forward(small F)
Answer by MILLIMEDIA · Nov 01, 2019 at 06:21 AM
Consider shooting with raycasts instead of a visible projectile. Have a look here