Raycast, Bullet Holes, and Random Arrays in Unity 3d

2017-11-05 1

In this Xenosmash tutorial we will be going over a few different things. First well discuss how to create a Raycast that well apply to the front of our weapon. Then well create bullet hole textures that will be randomly instantiated from an array using random.range in our script. This is useful for creating a random type of bullet texture every time we shoot. This makes it look more realistic as not every bullet hole will look exly the same every time.\r
\r
Start off by applying an empty game object to the front of your gun. We will create our raycast off of this empty game object. In this script well have the raycast visible in order to see how far it reaches and also to show you how a raycast works. We adjust the length of this raycast to 10 meters and a color of green.\r
\r
Afterward well include an array for our bullet hole textures. The reason we use an array is so that we can have more than one bullet hole texture to be instantiated. Whenever we shoot it will randomly instantiate a bullet hole texture, which looks more realistic. The bullet hole textures will rotate to fit the rotation of the object we shoot at.\r
\r
Scripts can be downloaded here: