- Home /
This question was
closed Feb 05, 2013 at 08:31 PM by
Eric5h5 for the following reason:
Question is off-topic or not relevant
Gun Script
Can I please have a gun script that shoots a prefab. The gun script I have is a Raycast.
var Range : float = 1000; //Range of gun
var Force : float = 1000; //Force of bullet on objects
var Clips : int = 20; //Number of clips
var BulletPerClip : int = 60; // Bullets in a clip
var ReloadTime : float = 3.3; //Time taken to reload
var BulletsLeft : int = 0;
var ShootTimer : float = 0;
var ShootCooler : float = 0.9; //Cooldown time after every shot
var Damage : int = 10; //Damage done to object by the gun
function Start () {
BulletsLeft = BulletsLeft;
}
function Update () {
if( ShootTimer > 0){
ShootTimer -= Time.deltaTime;
}
if( ShootTimer < 0){
ShootTimer = 0;
}
if(Input.GetKey(KeyCode.Q)){
if( ShootTimer == 0){
RayShoot();
ShootTimer = ShootCooler;
}
}
}
function RayShoot (){
var Hit : RaycastHit;
var DirectionRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.blue);
if(Physics.Raycast(transform.position, DirectionRay, Hit, Range)){
if(Hit.rigidbody){
Hit.rigidbody.AddForceAtPosition( DirectionRay * Force, Hit.point);
Hit.collider.SendMessageUpwards("ApplyDamage", Damage , SendMessageOptions.DontRequireReceiver);
}
}
BulletsLeft --;
if( BulletsLeft < 0){
BulletsLeft = 0;
}
if(BulletsLeft == 0){
Reload();
}
}
function Reload (){
yield WaitForSeconds( ReloadTime);
if ( Clips > 0){
BulletsLeft = BulletPerClip;
}
}
Please Reply ASAP.
TASNO :D
Comment
You don't ask for scripts out of the blue, take some time to learn or watch a tutorial.
This isn't a site to ask people to write scripts for you, it's for specific development questions.