I 'm curious how I would make something like this
Player presses a button causing a raycast, which makes an arc of electricity appear between him and the end of his raycast.
Now, I’m not sure how I would create the visual effect of the bolt. Would I instantiate something that is stretched between the player and the target? how would that work?
or would I make a 2d texture that tiles itself forward?
You can also create the effect procedurally. There is a procedural example program on the Asset store, made by Unity Techonologies, that has a lightning effect. You can find it here.
I think it could be accomplished with a prefab Particle System. Give the prefab a cone shape with angle zero so you have a cylinder, and set it up to your liking. When it gets instantiated, move it’s base (where the particles generate from) to the caster’s hand or wand or whatever, and turn it towards the target. Then you set the cylinder’s (cone’s) height to the distance between cster and target. You could also try to work with the stretched billboard length ratio settings.
You could do it with a single particle or add smaller ones that add sparks etc. for special effects.
I made an asset that does this and I think the bolts look very comparable to real lightning bolts. There is a web player example, as well as some videos and images.
Asset link: Unity Asset Store - The Best Assets for Game Making