Ejemplo n.º 1
0
    public static GameObject createGameObject(AbstractTrainCar trainCar,
                                              LogicEngine parent)
    {
        GameObject trainObject;

        //create my game object!
        if (trainCar.trainIndex == 0)
        {
            //engine
            trainObject = UnityEngine.Object.Instantiate(parent.trainEngine);
        }
        else if (trainCar.trainIndex == -1)
        {
            //caboose
            trainObject = UnityEngine.Object.Instantiate(parent.caboose);
        }
        else
        {
            trainObject = UnityEngine.Object.Instantiate(parent.trainCar);
            parent.setColorForGameObject(trainObject, trainCar.trainIndex);
        }
        var carHandler = trainObject.AddComponent <TrainCarHandler>();

        carHandler.trainCar    = trainCar;
        carHandler.trainObject = trainObject;
        carHandler.parent      = parent;
        return(trainObject);
    }