Unity 3.x Game Development Essentials Question

Well, I DID love this book, until I got to Chapter 2. I renamed the script “Shooter,” wrote the 3 lines of code called for on pg. 45, and then saved. When I tried to assign the script to the MainCamera, I got the following error message: “Assets/Standard Assets/Character Controllers/Sources/Scripts/ThirdPersonController.js(193,54): UCW0003: WARNING: Bitwise operation ‘|’ on boolean values won’t shortcut. Did you mean ‘||’?”

Huh? I didn’t touch the ThirdPersonController.js script.

Help!

For those who wonder how to fix this, that’s easy.
Just replace

if (Input.GetKey (KeyCode.LeftShift) | Input.GetKey (KeyCode.RightShift)){

with

if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift)){

I know it’s a little overdue, but there will be more people asking this :slight_smile:

Unity compiles all scripts in Assets or subfolders, thus any wrong script will cause errors or warning messages - even if you don’t even use it in your scene.

But don’t worry: the compiler is just giving a warning message, and this particular “problem” makes no difference at all (even if need to use that script).

SIDENOTE: This “error” is a small flaw in the 3rd person script:

if (Input.GetKey (KeyCode.LeftShift) | Input.GetKey (KeyCode.RightShift)){
    ...

The two expressions are booleans, and usually the logical OR (symbol ||) would be used to connect them. The logical OR allows shortcut of unnecessary boolean expressions: if the first expression is true, there’s no need to check the others - they are not evaluated, and the then code is directly executed. In the case above, the bitwise OR (|) requires that both expressions are evaluated and bitwise OR’ed. This makes no difference in this particular case, but could be a disaster in some others - that’s why Unity 3.5 included this kind of warning message.