void RandomEnable() { if (_inactiveEnemies.Count == 0) { return; } int randIndx = Random.Range(0, _inactiveEnemies.Count); Enemy enemy = (Enemy)_inactiveEnemies[randIndx]; if (Time.time - enemy.GetActiveTime() >= 5.0f) // Give breathing room before reactivation { _inactiveEnemies.RemoveAt(randIndx); if (Random.Range(1, 10) < 2.0f) { enemy.MakeFriendly(); _activeEnemies.Add(enemy); } else { enemy.Activate(Random.Range(1, _info.maxLevel)); _activeEnemies.Add(enemy); } _lastRandomTime = Time.time; } }
IEnumerator Pause(Enemy self) { self.Deactivate(); yield return(new WaitForSeconds(FREEZE_TIME)); self.Activate(); }
IEnumerator SpawnEnemy() { float spawnDelay = 1f; float tileFlashSpeed = 4f; Transform spawnTile = map.GetRandomOpenTile(); if (isCamping) { spawnTile = map.GetTileFromPosition(playerTransform.position); } Material tileMaterial = spawnTile.GetComponent <Renderer>().material; Color initialColor = Color.white; Color flashColor = Color.red; float spawnTimer = 0f; while (spawnTimer < spawnDelay) { tileMaterial.color = Color.Lerp(initialColor, flashColor, Mathf.PingPong(spawnTimer * tileFlashSpeed, 1)); spawnTimer += Time.deltaTime; yield return(null); } Enemy spawnedEnemy = Instantiate(enemy, spawnTile.position + Vector3.up, Quaternion.identity) as Enemy; spawnedEnemy.OnDeath += OnEnemyKill; // workaround for NavMeshAgent bug that I don't understand. yield return(null); spawnedEnemy.Activate(); spawnedEnemy.SetCharacteristics(currentWave.moveSpeed, currentWave.damage, currentWave.enemyHealth, currentWave.skinColor); }
public Enemy Activate(Vector3 position) { Enemy enemy = Pick(); if (enemy != null) { enemy.Activate(position); } return(enemy); }
/// <summary> /// エネミー用機体を作成(文字列から) /// </summary> public Enemy InstantiateEnemy(string componentName, ToolBox.ShipData shipData) { //色 Color c = enemyColor; //機体を生成 Ship ship = InstantiateShip(shipData, c); //エネミー用コンポーネントをアタッチする Enemy enemy = (Enemy)ship.gameObject.AddComponent(Type.GetType(componentName)); //有効化 enemy.Activate(this, "Enemy", "Enemy"); return(enemy); }
private Enemy WakeUp() { if (backupEnemies.Count <= 2) { if (spawnMore) { backupEnemies.Add(Spawn()); } } Enemy newEnemy = null; if (backupEnemies.Count > 0) { newEnemy = backupEnemies[0]; backupEnemies.RemoveAt(0); newEnemy.gameObject.SetActive(true); newEnemy.Activate(); currentEnemies.Add(newEnemy); } return(newEnemy); }
// todo create grid level base class and inherit from there // ran out of time... void GenerateGrid() { // im using a flag to minimise code duplication if (!isGridCreated) // Only create array on first run of the level { enemies = new GameObject [xMax, yMax]; } // init the grid for (int i = 0; i < xMax; i++) { for (int j = 0; j < yMax; j++) { if (!isGridCreated) // only instantiate gameobjects on first run of the level { enemies [i, j] = Instantiate(enemyPrefab, gameObject.transform); } Enemy enemy = enemies [i, j].GetComponent <Enemy> (); //cache script Vector3 enemyPosition = gameObject.transform.position - new Vector3(-yDistance * i, xDistance * j);; enemy.Activate(enemyPosition); States.EnemyType rng; // todo set type if (GameManager.Instance.config.isRandomColours) { rng = (States.EnemyType)(UnityEngine.Random.value * Enum.GetNames(typeof(States.EnemyType)).Length); } else { rng = States.EnemyType.Green; } enemy.SetEnemyType(rng); enemy.SetGridLocation(i, j); totalNumOfEnemies++; } } isGridCreated = true; ResetLastRowNumber(); }
private IEnumerator BeginGame() { //Instantiate Maze TogglePause(false); Camera.main.clearFlags = CameraClearFlags.Skybox; Camera.main.rect = new Rect(0f, 0f, 1f, 1f); mazeInstance = Instantiate(mazePrefab) as Maze; yield return(StartCoroutine(mazeInstance.Generate())); //Instantiate Player playerInstance = Instantiate(playerPrefab) as Player; IntVector2 coord = new IntVector2(0, 0); MazeCell currentCell = mazeInstance.GetCell(coord); MazeCell safeCell = mazeInstance.GetSafeCell(); MazeCell playerCell = currentCell; int maxDistance = 0; int sizeX = mazeInstance.size.x; int sizeZ = mazeInstance.size.z; for (int i = 0; i < sizeX; ++i) { coord.x = i; for (int j = 0; j < sizeZ; ++j) { coord.z = j; currentCell = mazeInstance.GetCell(coord); int distance = GetManhattanDistance(currentCell, safeCell); if (distance > maxDistance) { maxDistance = distance; playerCell = currentCell; } } } playerInstance.Activate(playerCell); playerCell.SetMaterialColor(Color.blue); playerInstance.treasureText = treasureText; //Instantiate Enemy enemyInstance = Instantiate(enemyPrefab) as Enemy; List <MazeCell> doors = mazeInstance.GetDoorCells(); coord = new IntVector2(0, 0); currentCell = mazeInstance.GetCell(coord); MazeCell enemyCell = currentCell; maxDistance = 0; sizeX = mazeInstance.size.x; sizeZ = mazeInstance.size.z; for (int i = 0; i < sizeX; ++i) { coord.x = i; for (int j = 0; j < sizeZ; ++j) { coord.z = j; currentCell = mazeInstance.GetCell(coord); int distance = GetManhattanDistance(currentCell, playerCell); if (distance > maxDistance) { maxDistance = distance; enemyCell = currentCell; } } } enemyInstance.Activate(enemyCell, doors); rockText.text = "Rocks: " + rockCount.ToString(); gameStarted = true; }
private void Update() { if (Input.GetMouseButtonDown(0)) { PointerEventData pointerData = new PointerEventData(EventSystem.current); pointerData.position = Input.mousePosition; List <RaycastResult> results = new List <RaycastResult>(); EventSystem.current.RaycastAll(pointerData, results); if (results.Count > 0) { if (results[0].gameObject.layer == LayerMask.NameToLayer("RetryUI")) { ResetGame(); } } if (inControl) { if (results.Count > 0) { if (results[0].gameObject.layer == LayerMask.NameToLayer("CarrotUI")) { selectedPlot.PlacePlant(plants[1], Team.PLAYER); seedCount -= plantCost; seedCountUI.text = "" + seedCount; if (!gameStarted) { opponent.Activate(); HideTutorialUI(); gameStarted = true; } } else if (results[0].gameObject.layer == LayerMask.NameToLayer("BeetUI")) { selectedPlot.PlacePlant(plants[0], Team.PLAYER); seedCount -= plantCost; seedCountUI.text = "" + seedCount; if (!gameStarted) { opponent.Activate(); HideTutorialUI(); gameStarted = true; } } else if (results[0].gameObject.layer == LayerMask.NameToLayer("OptionsUI")) { results[0].gameObject.GetComponentInParent <OptionsUI>().TogglePullDown(); } else if (results[0].gameObject.layer == LayerMask.NameToLayer("AudioButton")) { results[0].gameObject.GetComponentInParent <OptionsUI>().ToggleAudio(); } else if (results[0].gameObject.layer == LayerMask.NameToLayer("CamShakeButton")) { results[0].gameObject.GetComponentInParent <OptionsUI>().ToggleCamShake(); } else if (results[0].gameObject.layer == LayerMask.NameToLayer("QuitButton")) { Application.Quit(); } else if (results[0].gameObject.layer == LayerMask.NameToLayer("GrainPickup")) { Grain g = results[0].gameObject.GetComponentInParent <Grain>(); ChangeSeedCount(g.GrainValue); g.Interact(); } } else { if (seedCount >= plantCost) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Plot plot = hit.transform.GetComponent <Plot>(); if (plot != null) { if (selectedPlot == null) { selectedPlot = plot; selectedPlot.ShowPopup(); } else { selectedPlot.HidePopup(); if (selectedPlot != plot) { selectedPlot = plot; selectedPlot.ShowPopup(); } else { selectedPlot = null; } } } } } } } } }