Unity 5.6 - Cameras Not Snapping

I’m trying update a working game from old version of Unity5 (done by programmer no longer available). I upgraded to Unity 5.6 and the latest Unity, but cannot get old code to function correctly as before. There is no error messages, its either a Unity bug or something has changed that I’m not aware of. Here is a snipped of the code. The user should rotate the cameras in the scene etc. The code is messy…

trigger.isSnaped = (trigger.triggerType == TriggerType.normal) ? isBetween(rot.y, new Vector2(trigger.rotaion.y - trigger.snapDistance, trigger.rotaion.y + trigger.snapDistance)) && isBetween(rot.x, new Vector2(trigger.rotaion.x - trigger.snapDistance, trigger.rotaion.x + trigger.snapDistance)) && !Input.GetMouseButton(0) : trigger.hiddenBlock.IsBlocked (linecastPos);

That is an understatement. Whoever did this should have realized what they were doing but did it anyway. That is completely unreadable and incomprehensible, which means if anything goes wrong with it you’re basically out of luck (like has happened now).

Let’s unpack that a little bit.

trigger.isSnaped =
    (trigger.triggerType == TriggerType.normal) ?
        isBetween(
            rot.y,
            new Vector2(trigger.rotaion.y - trigger.snapDistance, trigger.rotaion.y + trigger.snapDistance)
        ) &&
        isBetween(
            rot.x,
            new Vector2(trigger.rotaion.x - trigger.snapDistance, trigger.rotaion.x + trigger.snapDistance)
        ) &&
        !Input.GetMouseButton(0)
    : trigger.hiddenBlock.IsBlocked (linecastPos);

I still have no idea what’s going on, but at least it’s readable.

1 Like

Thanks man, this what happens when you hire fresh out out of Uni coders, I think they did it on purpose.
Oh you dont want to see the rest of the file…