Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Lasergun : MonoBehaviour {
- public KeyCode shootKey = KeyCode.G;
- public float shootForce;
- GameObject laserShown;
- public AudioClip shootClip;
- public GameObject impactPrefab;
- public GameObject ghostHitPrefab;
- void Update () {
- if (Input.GetKeyDown (shootKey)) {
- GetComponent<AudioSource> ().PlayOneShot (shootClip);
- Ray r = new Ray (transform.position, transform.forward);
- RaycastHit hit = new RaycastHit ();
- if (Physics.Raycast (r, out hit)) {
- if (impactPrefab != null) {
- GameObject impactGO = GameObject.Instantiate(impactPrefab, hit.point, transform.rotation);
- //shot.GetComponent<Rigidbody>().AddForce(transform.forward * shootForce);
- }
- Lines.Make (ref laserShown, transform.position, hit.point);
- GhostMover gm = hit.collider.transform.GetComponent<GhostMover> ();
- if (gm != null) {
- gm.transform.position += transform.forward * shootForce;
- gm.SendMessage ("LaserHit");
- if (ghostHitPrefab != null) {
- GameObject impactGO = GameObject.Instantiate(ghostHitPrefab, hit.point, transform.rotation);
- //shot.GetComponent<Rigidbody>().AddForce(transform.forward * shootForce);
- }
- }
- } else {
- Lines.Make (ref laserShown, transform.position, transform.position + r.direction);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement