I have 2 float number, one is 1f, the other is 1.55f, but the product of them is 1.05f !!! what’s wrong with it?
here’s my code:
float heightByHeight = bizObj.Space.Size.y / 2;
float heightByWidth = bizObj.Space.Size.x / camera.aspect / 2;
//Debug.Log("heightByHeight:" + heightByHeight + ",heightByWidth:" + heightByWidth);
if (heightByHeight > heightByWidth)
size = heightByHeight * viewObjectRatio;
size = heightByWidth * viewObjectRatio;
Here’s the result in watch (on debugging)
And i quite sure that the program runs by the first branch:
Obviously, the correct result should be “1.55f”, but “1.05f”, such a large difference could not be caused by precision. But why?
Debug stops at the start of the line. size has not been updated yet.
fwiw in situations like that i usually just throw in the line int stop = 1; after it and put the breakpoint on it.
Well, i find the problem.
I defined a member variable name viewObjectRatio, and intended to override it in a subclass. But there’s no override keyword on variable in C#, so i used “new”, thought it playing like “override”, obviousely, it’s wrong.
now i change the code as following:
public class ViewRack : ViewBizObject
protected GameObject ruler;
public ViewRack(BizObject biz) :base(biz)
viewObjectRatio = 1.05f;
Then get the right result.
It’s my fault, but i have an execuse misdirected by Visual Studio, it’s watching view gave a value from subclass, which not used in running context.