FOV Script

Hello I am trying to learn making games but I am not good at programing. I have this script for FOV of an enemy that I got from couple years back. but after importing it i realized it doesn’t work properly.

The line leading from enemy to player should turn green from red when it is in FOV of enemy
but its color doesn’t change.

Could somebody please look in to the script and perhaps explain what exactly is wrong with it?

And sure I could just look up some tutorial and follow it,
but i want to understand why this script won’t work properly.

8205828–1070862–FOV_Detection.cs (2.44 KB)

Welcome to the forums @poblius23 , for the future, it’s better to use code tags and share only the relevant piece of code.

Looking at your script, it should be working as you described it. However, your inFOV variable is set only in the Update method which is called in the play mode. If you press play to enter play mode your script should be working fine.

If you want to make it work in the edit mode as well, you could add the ExecuteInEditMode attribute to your FOV_Detection class like this:

[ExecuteInEditMode]
public class FOV_Detection : MonoBehaviour
{
    // your class
}

Hope this helps!