- Home /
Shooting Lasers
I'm making a 3D space sim. What I need to know is how to create a laser, fire it, and make it explode when colliding with it's target. I've been looking around for a week now I can't find any scripts that work, even when I modify. Is there script that can help me? Thanks is advance
Try starting with basic tutorials, then search 'laser' here and on Google. What you're asking is a multi-step process; it's not (unless someone's in a very giving mood) a simple plug and play solution.
As you can see, I said, "I've been looking around for a week now." To clear that up, I meant, on google, on unity answers/forums and on other websites
Take a look at this : http://www.youtube.com/watch?v=ZQL$$anonymous$$EZzBIZE
Answer by DayyanSisson · Aug 04, 2011 at 06:24 AM
Ok. Now my problems have changed. All my "enemies" have damage receivers. Now, I need the lasers to damage to an object with a damage receiver. I also need to change the script where you can hold the button down and lasers shoot out continually. How should I write that in this script:
var Laser : Transform;
function Update ()
{
if(Input.GetButtonDown("Fire1"))
{
Instantiate(Laser, transform.position, transform.rotation);
}
}
Have you considered using a Particle System ins$$anonymous$$d with a World Particle Collider? It's far less intense than using this method.
Answer by CHPedersen · Aug 01, 2011 at 06:32 AM
There's a script that can help you! In fact, there is one that does exactly, to the letter, what you want. But it doesn't exist yet, because, err... You haven't written it yet. ;-)
Poor humor aside, the tool you need to model your laser is the LineRenderer. Look into that, and then study the procedural example projects here:
http://unity3d.com/support/resources/example-projects/procedural-examples.html
Your question asks for a little much to begin with - firing something, drawing a laser, colliding with something, making an explosion, those are all different pieces of functionality, and the code that makes it work isn't even one script. Ideally, you'd split that stuff into several classes. So you gotta break your problem down, and tone down your expectations a little in the beginning. Start by seeing if you can draw something with the LineRenderer. Anything. Then if you can't come back and present your issues with it, and you can get help with that. Then when you understand how the LineRenderer works, start working on how to direct it from the player character in whatever direction he's firing. Then if you have problems with that, come back for help, etc, etc. etc.
The essence of what I'm saying is:
Inspiration is fine. But you have to write your script yourself.
Define milestones, then accomplish those, step by step.
$$anonymous$$ade me smile this fellow neighbor of $$anonymous$$e. :-)
Answer by fireDude67 · Aug 01, 2011 at 06:24 PM
I guess I am in a "Very Giving Mood"
What you need to do is:
Model of Laser (Capsule is what worked for me, scale it by One axis until it looks like a laser)
Texture the model - Create a new Material, then assign the Default color to Red, then drag it onto the Laser model
Create a prefab with the Model - Create a new prefab, then drag the Laser model onto it.
Add script that makes it go forward: New JavaScript -> add these lines:
function Update() { transform.Translate(Vector3.forward * Time.deltaTime); }
5) add that script to your Prefab
Thats how you can create a laser. Later when I have more time i'll update for how to Fire the laser.
after fire laser how to detect collision pls tell and also how to stop it
nilesh026 , simply call a Destroy.
//Collision Just Happened.
Destroy(gameObject);
Your answer
![](https://koobas.hobune.stream/wayback/20220612163516im_/https://answers.unity.com/themes/thub/images/avi.jpg)