I created a gun in unity using ray casting. It works in the editor but not the build.

I watched a tutorial on how to make a gun in unity and it worked, it also worked in the build, for a while, then I guess I changed something because it no longer works in the build. I tried multiple solutions, but nothing worked, when I built the project, the bullets would shoot from bellow the character instead of the attack point I set with an empty game object. I finally decided to follow a different tutorial to fix my problem, this tutorial used ray casting, but the same problem occurred when building the project. I am new to coding in C#. How can I fix this?

Generally speaking you cannot just mix and match tutorials. They almost all stand on their own as separate things.

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step what is going on, otherwise you’re just mimicking without learning

When you do have a problem and you are confident you did everything perfectly, it is …

Time to start debugging your code / project!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

If you learn more about your problem space, here is how to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?