- Home /
Question by
EliteHedgehog56 · Aug 29, 2018 at 07:30 AM ·
inputlinerendererrayduration
add lifespan to rail beam (ray)
hey all. I modified a ray line script to add to my railgun/instagib rifle. So far it works but the beam only disappears when the fire button is released, can I change that to make the beam disappear on it's own instead of when the fire button is released. Thanks
here's the javscript:
@script RequireComponent (LineRenderer)
RequireComponent(AudioSource);
var audioSource: AudioSource;
var mouse : Vector2;
var hit : RaycastHit;
var range : float = 100.0;
var line : LineRenderer;
var lineMaterial : Material;
var ray : Ray;
var FireRate : float = 10; // The number of bullets fired per second
var lastfired : float;
var gunshot : AudioClip;
function Start()
{
line = GetComponent(LineRenderer);
line.SetVertexCount(2);
line.GetComponent.<Renderer>().material = lineMaterial;
line.SetWidth(0.1f, 0.25f);
audioSource = GetComponent.<AudioSource>();
}
function Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit, range))
{
if (Input.GetButton("Fire1"))
{
if (Time.time - lastfired > 1 / FireRate)
{
lastfired = Time.time;
line.enabled = true;
line.SetPosition(0, transform.position);
line.SetPosition(1, hit.point + hit.normal);
audioSource.PlayOneShot(gunshot, 0.7F);
}
}
else
line.enabled = false;
}
}
Comment
Your answer
Follow this Question
Related Questions
LineRenderer missing in build 1 Answer
Ray Over Mouse 1 Answer
ray=Camera.main.ScreenPointToRay(Input.touches[0].position); 1 Answer
Android Multi-Touch Issue 2 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers