/// <summary> /// Creates an environment at the given location, pos. /// </summary> /// <param name="towerPos"></param> public void CreateEnvironment(Vector2 pos, float?scaleFactor = null, string imagePath = "rectangle", Color?overlayColor = null, Rectangle?sourceRectangle = null, Vector2?scale = null) { if (InactiveEnvironmentList.Count > 0) { GameObject go = InactiveEnvironmentList[0]; InactiveEnvironmentList.Remove(go); go.components.RemoveAll(c => c is SpriteRenderer); go.AddComponnent(new SpriteRenderer(go, imagePath, 0f, 1f, scaleFactor, sourceRectangle, scale)); go.GetComponent <SpriteRenderer>().Color = overlayColor.HasValue ? overlayColor.Value : Color.White; AddActive.Add(InactiveEnvironmentList[0]); InactiveEnvironmentList.Remove(InactiveEnvironmentList[0]); } else { GameObject obj = new GameObject(pos); obj.AddComponnent(new SpriteRenderer(obj, imagePath, 0f, 1f, scaleFactor, sourceRectangle, scale)); obj.GetComponent <SpriteRenderer>().Color = overlayColor == null ? Color.Black : overlayColor.Value; obj.AddComponnent(new Environment(obj)); obj.LoadContent(GameWorld.Instance.Content); obj.AddComponnent(new CollisionRectangle(obj)); obj.GetComponent <CollisionRectangle>().LoadContent(GameWorld.Instance.Content); AddActive.Add(obj); } }