Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Sep 11, 2013 at 09:29 PM by lancer for the following reason:

Figured out a way to make lasers, using raycasting and lineRenderers

avatar image
0
Question by lancer · Sep 10, 2013 at 11:39 PM · javascriptraycastingline renderer

Make A Laser?

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EHogger · Sep 10, 2013 at 11:50 PM 0
Share

Line renderer can show whenever you want it to. Post your script for the laser so far.

avatar image lancer · Sep 11, 2013 at 12:24 AM 0
Share

Does Debug.DrawRay(); work in the compiled version of the game? Or just in the editor?

avatar image lancer · Sep 11, 2013 at 02:51 PM 0
Share

bump

1 Reply

  • Sort: 
avatar image
1

Answer by Benproductions1 · Sep 11, 2013 at 12:04 AM

Hello,

Did you forget to google it? Just type the title into google (as stated in the FAQ):
http://lmgtfy.com?q=Unity+Make+a+Laser

Hope this helps,
Benproductions1

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RyanZimmerman87 · Sep 11, 2013 at 01:00 AM 0
Share

To be fair I personally found setting up a nice laser to be one of the more difficult aspects of my current project, and there are still aspects of it I wish to improve even with extensive google searches. But it does seem that some people don't search enough or at all before asking questions here.

Can be difficult to tell who is just new to program$$anonymous$$g and/or lazy and who is trying their best for many hours/days but still can't figure something out.

It does look like his code is a little bit light for someone who gave serious effort.

avatar image lancer · Sep 11, 2013 at 01:08 AM 0
Share

I did clean my code up a bit before posting, and have been trying to do this all day. I have a week and a half deadline to do this, so some help would be appreciated.

avatar image Benproductions1 · Sep 13, 2013 at 07:02 AM 0
Share

@lancer if my answer answered your question (or helped you do it) you should accept my answer ins$$anonymous$$d of closing the question. Closed questions usually means "bad question" :)

avatar image lancer · Sep 13, 2013 at 04:12 PM 0
Share

Your answer didn't help, sorry, I figured out my own way of doing it.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio play problem on raycast hit colider.gameObject.tag 1 Answer

Raycast object as far as possible? 1 Answer

ray cast not working ? 2 Answers

Detect face of cube clicked 4 Answers

Raycast script help? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges