【发布时间】:2014-08-20 01:21:19
【问题描述】:
我正在尝试将 Unity UnityScript 转换为 C#。我收到此错误:
资产/脚本/BoostPlatformCheck.cs(40,36):错误 CS0019:操作员
==' cannot be applied to operands of typeint' 和 `object'
这里是 C# 代码:
int collidedWith = collisionInfo.gameObject.GHetInstanceID();
ArrayList collided = new ArrayList();
....
if(collidedWith == collided[collided.Count - i - 1])
{
alreadyExists = true;
return;
}
当我将它从 JS 转换为 C# 时,我将 Array 更改为 ArrayList,并将 collided.length 更改为 collided.Count。
【问题讨论】:
-
试试:
if(collidedWith ==Convert.ToInt32(collided[collided.Count - i - 1])) -
您的
ArrayList中存储了什么?如果它们都是一样的——看起来它们是一样的;ints - 那么您应该使用List<int>.. 这将允许您进行比较。另外,不要按照蒂姆在此评论上方所说的去做。 -
我很震惊蒂姆的评论有一个赞成票——它是 2014 年的人——我们为此提供了强类型容器。您不应该从 .NET 2 及更高版本的
ArrayList转换对象。在这个简单的例子中肯定不会。 -
它也是 UnityScript,而不是 JavaScript
标签: c# unity3d unityscript code-conversion