//TODO not able to spawn on start, needs to be reworked public IEnumerator SpawnPlayerCharacter() { yield return(new WaitForSeconds(spawnDelay)); if (BlockGridRenderer.Singleton != null && BlockGridRenderer.Singleton.entrance != null) { Vector3 characterSpawnPosition = BlockGridRenderer.Singleton.entrance.spawnPositions[activeCharacters.Count % 2].position; CharacterControl character = Instantiate(characterPrefab, characterSpawnPosition, Quaternion.Euler(Vector3.zero)) .GetComponent <CharacterControl>(); character.name = "Character" + (activeCharacters.Count + 1); activeCharacters.Add(character); GridCoordinates startPos = BlockGridController.Singleton.grid.startingPosition; GridCoordinates randomCoordinatesInsideRoom = new GridCoordinates( startPos.x + Random.Range(BlockGrid.startingRoomLeftRearCorner.x, BlockGrid.startingRoomFrontRightCorner.x), startPos.y + Random.Range(BlockGrid.startingRoomLeftRearCorner.y, BlockGrid.startingRoomFrontRightCorner.y) ); UnitToolbar.Singleton.AddUnitButton(character.name); yield return(new WaitForSeconds(0.1f)); //TODO rework and refactor target picker script. Need some kind of Move() method for CharacterControl to move him to given Vector3 PlaceTargetWithMouse targetPicker = character.targetPicker; targetPicker.transform.position = randomCoordinatesInsideRoom.GetPositionOffset(targetPicker.surfaceOffset); character.transform.SendMessage("SetTarget", targetPicker.transform); } yield return(null); }
IEnumerator FindTargetWithMouse() { while (placeTarget == null) { placeTarget = GameObject.FindObjectOfType <PlaceTargetWithMouse>(); yield return(new WaitForSeconds(0.5f)); } placeTarget.setTargetOn = gameObject; }
private void SpawnTargetPicker() { _targetPicker = Instantiate( CharactersController.Singleton.targetPickerPrefab, BlockGridController.Singleton.grid.startingPosition.GetPositionOffset(), Quaternion.Euler(Vector3.zero) ).GetComponent <PlaceTargetWithMouse>(); _targetPicker.name = name + "'s target picker"; _targetPicker.setTargetOn = gameObject; //Will be activated by buttons on UnitToolbar _targetPicker.enabled = false; }