【发布时间】:2018-01-02 22:22:37
【问题描述】:
我是 C# 新手,我不知道为什么我在这些代码行中收到以下错误。
“错误 CS0266:无法将类型 'double' 隐式转换为 'float'。存在显式转换(您是否缺少强制转换?)”
float rightEdgeOfFormation = (float) transform.position.x + (width * 0.5);
float leftEdgeOfFormation = (float) transform.position.x - (width * 0.5);
我认为写作(浮动)是演员?
非常感谢!
【问题讨论】:
-
我认为这只是你的括号。
float rightEdgeOfFormation = (float) (transform.position.x + (width * 0.5)); -
请记住,当你写一些像
0.5这样的想法时,它会被解释为double值,如果你希望它是float,请将f添加到0.5f这样的数字末尾。