【发布时间】:2012-02-21 22:27:46
【问题描述】:
我正在尝试创建一个碰撞检测系统,其中每个游戏对象通过检查它所碰撞的游戏对象的类型来对其他游戏对象做出不同的反应。
我不断得到:
“Rat”是一种“类型”,但用作“变量”。
这是我用来检测哪种类型的对象碰撞并决定当一个对象与另一个特定类型的对象发生碰撞时要做什么的代码:
switch (other.Type) {
case Rat:
float tooClose = (Radius * 2) - distance.Length();
distance.Normalize();
PositionAfterCollisions += distance * tooClose * 0.5f;
VelocityAfterCollisions = -Velocity;
}
'other' 在这里是对碰撞列表中游戏对象的引用。
这是来自类/GameObject的顶部我试图识别+它继承自的类:
public enum ObjectType
{
Default,
Player,
Rat,
Cheese,
Trap,
Home
}
public ObjectType Type = ObjectType.Rat;
【问题讨论】: