Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

How to shoot RayCast in center of screen?

$
0
0
I need some scripting help My Code #pragma strict var damage : float = 1; var bulletsinclip = 30; var bulletsperclip = 30; var clips = 3; private var nextFireTime = 0.0; var fireRate = .02; function Update () { if (Input.GetKeyDown (KeyCode.R)){ Reload(); } if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) animation.CrossFade("Move"); else animation.CrossFade("Idle"); if (Input.GetKeyDown (KeyCode.G)){ animation.Play("select"); } if (Input.GetKeyDown (KeyCode.H)){ animation.Play("Put Away"); } if(Input.GetMouseButton(0)){ if (Time.time - fireRate > nextFireTime) nextFireTime = Time.time - Time.deltaTime; while( nextFireTime < Time.time && bulletsinclip != 0) { FireOneShot(); nextFireTime += fireRate; } } } function Reload(){ animation.Play("Reload", PlayMode.StopAll); bulletsinclip = bulletsperclip; clips --; } function FireOneShot(){ animation.Play("Auto"); bulletsinclip -= 1; var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit; var localOffset = GameObject.Find("GunTip").transform.position; if (Physics.Raycast (localOffset, direction, hit, 300)) { Debug.DrawLine (localOffset, hit.point, Color.cyan); // - send damage to object we hit - \\ hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver); } } function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "Ammo: " +bulletsinclip); GUI.Label (Rect (10, 30, 100, 20), "Bullets Left: " +clips * 30); } I understand that the "bullets" (raycast) shoots from the guntip but how do i make it go to the center of the screen?

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>