public void RemoveObstaclesUsed(ObstacleSettings obstacleSetting) { int obstacleType = (int)obstacleSetting.Obstacle.GetComponent <ObstacleParent>().GetObstacleType(); List <ObstacleSettings> obstacleSettings = (List <ObstacleSettings>)_obstaclesUsedNEW[obstacleType]; if (obstacleSettings.IndexOf(obstacleSetting) > -1) { obstacleSettings.Remove(obstacleSetting); _obstaclesUsedNEW[obstacleType] = obstacleSettings; } }
private void InstantiateObstacleGameObject(GameEntity obstacleEntity) { ObstacleType obstacleType = obstacleEntity.obstacleType.Value; ObstacleSettings obstacleSettings = SettingsService.GetObstacleSettings(obstacleType); GameObject obstacleObject = Object.Instantiate( obstacleSettings.Prefab ) as GameObject; obstacleEntity.AddGameObject(obstacleObject); PutInPosition(obstacleObject, obstacleEntity); }
public static ObstacleSettings GetObstacleSettings(ObstacleType obstacleType) { try { GameEntity settingsEntity = Contexts.sharedInstance.game.settingsEntity; ObstacleSettings settings = settingsEntity.obstaclesSettings.Map[obstacleType]; return(settings); } catch (System.Exception exception) { Debug.LogError(string.Format("Could not find obstacle settings for the type {0}: {1}", obstacleType, exception.Message)); } return(new ObstacleSettings()); }
//Gets a random obstacle from our set of prefabs. Will either get one from the pool, //or create one if there aren't any available. GameObject getRandomObstacle() { //Get a random prefab from the array of prefabs "obstaclePrefabs" GameObject prefabToUse = obstaclePrefabs[Random.Range(0, obstaclePrefabs.Length)]; GameObject obstacleToReturn = newObject(prefabToUse); ObstacleSettings settings = obstacleToReturn.GetComponent <ObstacleSettings>(); settings.setName(prefabToUse.name); settings.setDangerous(true); //We now have a GameObject stored in "obstacleToReturn". We should now set it's position accordingly. //reset it's position to be within the range minObstacleGap -> maxObstacleGap of the last obstacle in //"obstacles" float lastPosX = spawnPosition.x; float add = 0; if (obstacles.Count > 0) { GameObject lastObstacle = obstacles[obstacles.Count - 1]; add = lastObstacle.GetComponent <Collider>().bounds.size.x / 2f; lastPosX = lastObstacle.transform.position.x; } float createXPosition = lastPosX + Random.Range(minObstacleGap, maxObstacleGap); //prefabToUse.GetComponent<ObstacleSettings>.CreateY <-- choose Y with something like this? float z = randomLaneZ(); if (obstacleToReturn.GetComponent <ObstacleSettings>().three_lanes_wide) { z = RunnerControls.centerZ; } Vector3 translation = new Vector3(createXPosition, 0, z); obstacleToReturn.transform.position = translation; return(obstacleToReturn); }
void OnCollisionEnter(Collision col) { ObstacleSettings settings = col.gameObject.GetComponent <ObstacleSettings>(); if (settings != null) { if (settings.isDangerous()) { // Vector3 impulse = col.impulse; // if (impulse.x > 10) { GameController.setObstacleSpeed(0); GetComponent <Rigidbody>().freezeRotation = false; GameController.setGameOver(); // } else { // GameController.setObstacleSpeed(GameController.startObstacleMoveSpeed/2f); //} } } }