Quantcast
Channel: Latest Questions by lancer
Viewing all articles
Browse latest Browse all 72

Make A Laser?

$
0
0
I'm trying to make a laser for a weapon in a space ship game I'm making but not having much luck. I've tried using raycasts and a line renderer but then the line only shows when you hit something and I need it to show all the time. Does anyone have any ideas? I'm using unity free and JavaScript. **EDIT**: here is my script so far: #pragma strict var LRenderer : LineRenderer; function Start () { gameObject.AddComponent(LineRenderer); LRenderer = GetComponent(LineRenderer); LRenderer.SetPosition(0, transform.position); LRenderer.SetPosition(1, transform.position); LRenderer.SetColors(Color.blue, Color.white); } function Update () { var ray = new Ray (transform.position, transform.forward); var hit : RaycastHit; if(Input.GetKey(KeyCode.Space)){ if(Physics.Raycast(ray, hit)){ LRenderer.SetPosition(0, ray.origin); LRenderer.SetPosition(1, hit.point); } } } The issue is I can figure out how to make the ray be drawn while shooting as well as when it hits. It this case the linerenderer only shows when the ray hits, and I want it to show while the ray is firing along the ray.

Viewing all articles
Browse latest Browse all 72

Trending Articles



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