Example #1
0
        private void Start()
        {
            if (gameObjectSpawner == null)
            {
                gameObjectSpawner = FindObjectOfType <GameObjectSpawner>();
            }

            gameObjectSpawner[currentCheckpoint].Spawn();
        }
    void Spawn(GameObject myGameObject)
    {
        GameObjectSpawner spawnerCode = myGameObject.GetComponent <GameObjectSpawner>();

        nextSpawn = Time.timeSinceLevelLoad + minSpawnDelay;

        SpawnPos = spawnerCode.GetSpawnPos();
        GameObject newHelp = Instantiate(myGameObject, SpawnPos, Quaternion.identity) as GameObject;

        newHelp.transform.parent = this.transform;

        lastSpawn = spawnerCode.myType;
        spawnCount++;
        if (spawnCount % incrementRate == 0)
        {
            scrollSpeed += scrollIncrement;
        }
    }
        private static GameObject BuildGameObject(XElement sourceElement, IServiceProvider services)
        {
            string     typeName = XParser.GetString(sourceElement, "type");
            GameObject gameObject;

            switch (typeName)
            {
            case "MegamanX.GameObjects.Playable.Player":
                Player player = new Player((IKeyboardDevice)services.GetService(typeof(IKeyboardDevice)));
                gameObject = player;
                break;

            case "MegamanX.GameObjects.GameObjectSpawner":
                GameObjectSpawner spawner       = new GameObjectSpawner();
                string            spawnTypeName = XParser.GetString(sourceElement, "spawntype");
                Type spawnType = Type.GetType(spawnTypeName);
                if (!typeof(GameObject).IsAssignableFrom(spawnType))
                {
                    throw new TypeLoadException($"'{spawnTypeName}' is not a valid spawnable GameObject.");
                }
                spawner.SpawnType = spawnType;
                gameObject        = spawner;
                break;

            default:
                var type = Type.GetType(typeName);
                if (!typeof(GameObject).IsAssignableFrom(type))
                {
                    throw new TypeLoadException($"'{typeName}' is not a valid GameObject.");
                }
                gameObject = (GameObject)Activator.CreateInstance(type);
                break;
            }

            float x = XParser.ParseFloat(sourceElement, "x");
            float y = XParser.ParseFloat(sourceElement, "y");

            gameObject.Position = new Vector2(x, y);

            return(gameObject);
        }
 protected override void Awake()
 {
     base.Awake();
     isDead  = true;
     spawner = GetComponentInChildren <GameObjectSpawner>();
 }