Hi, I'm very new to Unity and I'm currently trying to make my first Unity game, which is a survival game à la stranded on an island and I have a big problem:

As of now the Character (First Person Controller) should be able to chop down trees, but it's not always working. The Tree is just a standard 3D Model with a Box Collider just as big as its trunk. The Purpose of it is so that I can check what I hit with a RayCast and if it's a tree, then the tree's health should be reduced.

Unfortunately though it's not always working, I've already tried going closer to/farther away from the tree and also moving the camera up and down, but most of the times nothing happens.

Here is the code of the Script used for Chopping the tree:

RayCast Script :


Edit: Whenever I remove the RayCast-Script from the Main Camera and add it there again, then the Tree Chopping suddenly works completely fine. However when I save it, close the scene and open it again, the problem pops up again.

I've already tried looking around in the internet, but I haven't found anything which might help me out, and I would like to have it fixed.

Please help.