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

Gun Recoil

$
0
0
Hello today I have been struggling with a recoil script please help me fix this script please, thanks! Here's my shoot script preferably attach a recoil script onto to this, Im new to scripting also so explain the script please. var Effect : Transform; var TheDammage = 30; var SpawnTo: Transform; var Gun : Transform; var AudioShot: AudioClip; var muzzleFlash : Renderer; var muzzleLight : Light; function Start() { muzzleFlash.enabled = false; muzzleLight.enabled = false; } function OnTriggerEnter(hit:Collider) { if(hit.gameObject.tag == "Player") { Gun.parent = SpawnTo; Gun.transform.position = SpawnTo.transform.position; Gun.transform.rotation = SpawnTo.transform.rotation; } } function Update () { var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.52, Screen.height*0.5, 0)); if ((transform.parent != null) && Input.GetMouseButtonDown(0)) if(Input.GetButtonDown("Fire1")) { Shoot(); } if ((transform.parent != null) && Input.GetMouseButtonDown(0)) if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast (ray, hit, 100)) { audio.PlayOneShot(AudioShot,0.7); var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(particleClone.gameObject, 2); hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver); } } } function Shoot() { muzzleFlash.renderer.enabled = true; muzzleLight.enabled = true; yield WaitForSeconds(0.1); muzzleFlash.renderer.enabled = false; muzzleLight.enabled = false; }

Viewing all articles
Browse latest Browse all 592

Trending Articles



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