can anybody give me a script for a weapon of some sort
2 Answers
2Here's a script for a weapon:
// Insantiate a rigidbody then set the velocity
var projectile : Rigidbody;
var speed = 50;
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 * speed);
}
}
Put it on your camera. Next, drag the object you wish to use for your bullet onto the empty slot in the inspector. Hope this helps!
You'll also want to ignore collisions between the projectile and the collider of the player, otherwise your bullets are likely to fly off in random directions because they're hitting your own player :-)
– duckHave a go at this: http://unity3d.com/support/resources/tutorials/fpstutorial
If you want to skip reading the tutorial, you can download the completed project files to see how it was made.
You ought to be more specific about what you want to achieve. The scripting involved in various weapon types (laser, rocket launcher, sword, grenade, etc) are all very different.
– duckYour network is very complicated. I can see a few spots are unreachable when they should be. For example, if you jump, you have to go through all those extra transitions and wait for three animations before you are back on the idle animation. In the meantime, if you punch, you have to wait until the active node is idle to see the punch again. Also, none of the separate punches are connected, so if you do a right hook, you have to wait for the right hook to end before being able to do another kind of punch. That would explain why it looks like inputs are being dropped.
– Adam_g