I have this simple code:
The function CalculatePositions() is called every frame, although all parts inside the if-statment are logically false. Also debugging / stepping through returns false.
Any idea?
I have this simple code:
The function CalculatePositions() is called every frame, although all parts inside the if-statment are logically false. Also debugging / stepping through returns false.
Any idea?
Canvas.scaleFactor is a float.
Due to floating point precision issues it is possible that “width” will never be truly equal to “pixelWidth/scaleFactor”.
Never came across this yet.
But how to solve this?
First, you can just copy&paste the code, don’t do screenshots, that prevents making edits or quoting relevant parts.
You can solve this in two ways: cast or round the division calculation to int, then compare. Or do not compare for equality but a given range, ie it must be less than width+0.1f and more than width-0.1f. You can use Mathf.Approximately(…) to do this.
I tried so but using the codeformat gave me unwanted linebreaks, wrong line starts etc.
I wasn´t able to get it looking ok, so after some minutes I gave up… ![]()
That solved it - thanks!
Firstly, this is part of scripting forum, not general discussion.
You should know that, since you are member for years. So please do not abuse General Forum to get attention and faster responses.
Secondly, if having too many properties and conditions inside if statement, then take them out of if statement, so is easier to debug.
Since I can not copy line of code from the example, you do something like this.
Bool conditionA = your logic;
Bool conditionB = your logic;
Bool resultCondition = conditionA || conditionB;
if (resultCondition)
{
My logic
}
Now debugging is much easier for you, as you can put values into watchdog, or breakpoints at specific condition.
BTW, pasting code frof IDE to code is simple. Sometime indentations may be bigger, but that is not an issue in general. Just please use code formatting in the future.
People don’t have issue pasting code snippets directly.
Is cleaner and more convenient to work with on the forum.
Don’t try to fight formatting.
I’ll move your post to the Scripting forum where it belongs.
Thanks.