what is #pragma strict?

I’m trying to use collider.raycast but it gave me the following error MissingMethodException: Method not found: 'UnityEngine.Collider.Raycast'.

So I checked again the docs and there’s #pragma strict there, which I don’t know what it is, but doc files says it’s there because of a “UnityJS issue”

So I add #pragma strict at the top of everything, but now the whole code doesn’t work anymore. It gives me a whole bunch of new errors like

Assets/Scripts/fishAI.js(13,10): BCE0019: 'transform' is not a member of 'Object'.

It’s like it doesn’t recognize my global variables anymore…

If I delete #pragma strict code goes back to normal, but I still can’t use collider.raycast

Strict means enforced typing. You need to explicitly state what type each variable is. You cannot let the compiler decide, nor can you just make a random name and expect the compiler to instantiate a variable for you.

This is regularly good practice, but not enforced normally in UnityScript.

1 Like

How do I state what type each variable is?

for example in… bobby.transform.Rotate(-90,90,0); with #pragma strict that gives me an error, how do I fix that?

I think he means like this:

var myVariable : float = 1.000;

What is bobby variable ?

Great, I got it now!

@AkilaeTribe
bobby is a GameObject, so to fix it I had to specify what it is when I created it like this:

private var bobby : GameObject;

instead ofprivate var bobby;

thanks!

1 Like