I need help with my bullet and gun script

Hello all,
I am having a problem because i have ‘Bullet script’ which is basically raycast script and ‘Gunscript’ where there is all the stuff for gun aiming shoting.
My problem is that i need to make ‘damage, power, max dist’ script from bullet script to gun script, because i dont want all guns to have the same damage, i need to transfer somehow this from my raycast script to bullet script can any one help me i have no idea :frowning: .

i need to transfer damage,max dist,power from bullet script to gun script
[Yeah i now the easy way to copy all the code from bullet to gun script but after i would have to assign all of the particles, bullet holes and everything to each gun. Is there any other option ?

Thanks for helping!

when you instantiate the bullet store the reference into a gameobject variable… you can then set it’s properties immediately after the instantiate.

something like the second example on that page ^^

Hmmm still dont get it so i should add something like this but how [Can someone tell me ] do i need to add this to bullet script or where ?
// Instantiate a rigidbody then set the velocity
var projectile : Rigidbody;
function Update () {
// Ctrl was pressed, launch a projectile
if (Input.GetButtonDown(“Fire1”)) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);

// Give the cloned object an initial velocity along the current
// object’s Z axis
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
}
}

?

It might be just me, but you are thinking backwards about this in my mind… whenever I made a gun my gun script did all the driving and told my bullets the info they needed and not the other way around.

Anyway… you spawn a bullet already in your gun script via this line

//line 46,47 and 63, 64
if (bullet)
                Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);

in order for you to grab any info from your bullet, you need to have a reference to it as they said above…

// do this instead
if (bullet)
                GameObject newBullet = Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation); // now you have a reference called newBullet

you say you need to grab info from your bullet back to your gun… but the info you want to grab I don’t see where your gun will use this info. there doesn’t seem to be corresponding variables or any place that looks like it will use this grabbed info

    // you could cache the bullet component instead to only use get component once
    // ...but this will work for now

    /*where ever your gun needs this*/ = newBullet.GetComponent<bullet>().Damage;
    /*where ever your gun needs this*/ = newBullet.GetComponent<bullet>().power;
    /*where ever your gun needs this*/ = newBullet.GetComponent<bullet>().maxDist; // or maxDistance... i see you have it both ways

I’d rethink your gun script and make it a little easier, but if not you can use the above method to grab info from your bullets from inside your gun script…

Sorry I always do c# so if anyone can see where I screwed up for Unity Script please correct me

Sorry i still dont get it :frowning:
Basically all i want is to have ‘var damage’ inside of gunscript, not in bullet because i dont want all gun give the same damage.

?

Anyone?