Iv been having some large problems trying to get my gun to use raycast rather then fire an actual bullet. Heres the script. I want the raycast to use the bullets count, and i want it to work. I am getting extremely frustrated. Iv been working at it for days, and i have still no fix for the problem. I also want to keep in mind that this script will be use for a multiplayer game, with networking.
Thanks.
var Bulletspawn : GameObject;
var BulletShellSpawn : GameObject;
var fireRate : float = 0.1;
var ReloadRate : float = 1;
var projectile : Rigidbody;
var BulletShell : Rigidbody;
var bullets = 10;
var MagazineCount = 2;
var speed = 100;
var ShellSpeedy = 100;
var ShellSpeedx = 100;
private var nextFire = 0.0;
private var Reload = 3.5;
function Update () {
if(MagazineCount>=1)
{
if(bullets>=1)
{
if(Input.GetButton("Fire1")&&Time.time > nextFire){
animation.PlayQueued ("shoot");
audio.Play ();
nextFire = Time.time + fireRate;
var hit : RaycastHit;
var direction : Vector3 = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position.BulletSpawn , direction * Range , Color.blue);
if(Physics.Raycast(BulletSpawn.transform.position , direction , hit, Range)){
var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
if(hit.collider.gameObject.tag == "Untagged"){
clone = Instantiate(BulletShell,BulletShellSpawn.transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (ShellSpeedx, ShellSpeedy, 0));
bullets -= 1;
Destroy (clone.gameObject, 10);
}
if(bullets<=0)
MagazineCount -= 1;
}
else
{
if(Input.GetKey("r")&&Time.time > nextFire){
animation.PlayQueued ("reload");
nextFire = Time.time + Reload;
bullets = 30;
}
}
}
}
}
function OnGUI()
{
GUILayout.Label( " Magazine = " + MagazineCount );
GUILayout.Label( " Bullets = " + bullets );
}