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~
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/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