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

Rapid Laser?

$
0
0
I'm trying to make my lasers shoot rapidly instead of shooting a long line here is my code, thanks! using UnityEngine; using System.Collections; public class LaserScript : MonoBehaviour { LineRenderer line; void Start () { line = gameObject.GetComponent(); line.enabled = false; } void Update () { if(Input.GetButtonDown("Fire1")) { StopCoroutine("FireLaser"); StartCoroutine("FireLaser"); } } IEnumerator FireLaser() { line.enabled = true; while(Input.GetButton("Fire1")) { Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; line.SetPosition(0, ray.origin); if(Physics.Raycast(ray, out hit, 100)) { line.SetPosition(1, hit.point); if(hit.rigidbody) { hit.rigidbody.AddForceAtPosition(transform.forward* 10, hit.point); } } else line.SetPosition(1, ray.GetPoint(100)); yield return null; } line.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>