【问题标题】:Detect type/enum for purposes of collision between different game objects/classes为不同游戏对象/类之间的碰撞检测类型/枚举
【发布时间】: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;

【问题讨论】:

    标签: c# enums


    【解决方案1】:

    在 C# 中,枚举始终由名称限定。

    你需要

    case ObjectType.Rat:
    

    【讨论】:

    • 现在我得到了这个错误:Control cannot fall through from a case label ('case 2:') to another
    猜你喜欢
    • 2023-03-24
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多