//下面是CreateCar和createGongju的具体实现

//创建车辆 GameObject CreateCar(int carNum,int enterDir,int exitDir,int startRotation,int endRotation,float distance,float pos) { GameObject car = Instantiate(CarPfab); car.name = 'car' + carNum.ToString();

    Car carScript = car.GetComponent<Car>();
    carScript.carNum = carNum;
    carScript.enterDir = Dir[enterDir];
    carScript.exitDir = Dir[exitDir];
    carScript.startRotation = Rotation[startRotation];
    carScript.endRotation = Rotation[endRotation];
    carScript.distance = distance;
    carScript.startPos = getStartPos(enterDir, pos);

    return car;
}

//创建工具车 GameObject createGongju(int type, int dir, float pos) { GameObject car = Instantiate(CarGongju); car.name = 'gj' + type.ToString() + dir.ToString() + pos.ToString();

    CarGongju carScript = car.GetComponent<CarGongju>();
    carScript.type = type;
    carScript.dir = Dir[dir];
    carScript.startPos = getStartPos(dir, pos);

    return car;
}

//根据输入的方向和横向位置,计算车辆的初始生成位置 Vector3 getStartPos(int enterDir, float pos) { switch (enterDir) { case 1: return new Vector3(pos, 0, -15); case 2: return new Vector3(15, 0, -pos); case 3: return new Vector3(-pos, 0, 15); case 4: return new Vector3(-15, 0, pos); default: return Vector3.zero; } }

Unity C# 代码:车辆生成与管理 - MANAGER 脚本

原文地址: https://www.cveoy.top/t/topic/nu6N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录