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 /
avatar image
0
Question by Codex1770c · Feb 02, 2011 at 08:47 PM · javascriptfpsgunlaser

I need help with a firing script

Ok, well I am making an fps with as much "eyecandy" as possible but I am at a loss. I am new to unity and just got finished with a C# class so I am decent with programming but with unity I seem helpless. I need code to be able to spawn a laser at a certain point when I press the "fire1" commmand. How would I make this laser? How do I make the laser appear where I want like an fps. Thankyou very much for any help you can give me~

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Design3.com · Feb 02, 2011 at 09:08 PM

The input code is:

if (Input.GetButtonDown("Fire1")) {
}

You should cast a ray into the world and find out what the hit point is. You can then use a line renderer to draw a line from your gun barrel to the hit point. You can also animate the start and end of the line of you want using a Lerp function.

Design3 has a walkthrough of animating a line renderer laser and of casting a ray from a screen point into the world upon mouse click:

https://www.design3.com/unity/feature-a-techniques/unity-particle-effects/item/556-chapter-11-scifi-effects-laser

https://www.design3.com/unity/game-builds/knights-3d-game/item/317-chapter-6-raycast-collider-setup

====Documentation Links====

Input:

http://unity3d.com/support/documentation/Components/class-InputManager.html

http://unity3d.com/support/documentation/ScriptReference/Input.GetButtonDown.html

Raycasting:

http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenPointToRay.html

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

http://unity3d.com/support/documentation/ScriptReference/RaycastHit.html

Line Renderer:

http://unity3d.com/support/documentation/Components/class-LineRenderer.html

Animating points:

http://unity3d.com/support/documentation/ScriptReference/Vector3.Lerp.html

Comment
Add comment · Show 1 · 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 Codex1770c · Feb 02, 2011 at 09:19 PM 0
Share

hey, well thank you very much! This was exactly what I needed!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Gun Firing help? 2 Answers

How to let my gun shoot ?? 0 Answers

Some issues with weapon switching and reloading? 2 Answers

crosshair scrip not working 1 Answer

How can I convert this script to automatic fire? 2 Answers


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