Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //****** Donations are greatly appreciated. ******
- //****** You can donate directly to Jesse through paypal at https://www.paypal.me/JEtzler ******
- var shotSound : AudioClip; // drag a shot sound here, if any
- var bloodPrefab : GameObject; // drag the blood prefab here, if any
- var sparksPrefab : GameObject; // drag the sparks prefab here, if any
- var crosshair : Texture2D;
- function Start () {
- Screen.showCursor = false;
- }
- function OnGUI () {
- GUI.DrawTexture(Rect(Screen.width/2,Screen.height/2,64,64), crosshair);
- }
- function Update () {
- if(Input.GetMouseButtonDown(0)){
- Shoot();
- }
- }
- function Shoot () {
- if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound
- var hit: RaycastHit;
- if (Physics.Raycast(transform.position, transform.forward, hit)){
- // prepare rotation to instantiate blood or sparks
- var rot = Quaternion.FromToRotation(Vector3.up, hit.normal);
- if (hit.transform.tag == "Enemy"){ // if enemy hit...
- if (bloodPrefab) Instantiate(bloodPrefab, hit.point, rot); // make it bleed...
- hit.transform.SendMessage("ApplyDamage", 5, SendMessageOptions.DontRequireReceiver); // and consume its health
- } else { // otherwise emit sparks at the hit point
- if (sparksPrefab) Instantiate(sparksPrefab, hit.point, rot);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement