private void Awake() { layout = FindObjectOfType <TileLayout>(); place = FindObjectOfType <PlaceObjects>(); tileCountX = layout.getTileCountX(); tileCountY = layout.getTileCountY(); }
private GameObject CreateTile(int xIndex, int yIndex) { GameObject terrain = Instantiate( terrainTilePrefab, Vector3.zero, Quaternion.identity, Level ); //had to move outside of instantiate because it's a local position terrain.transform.localPosition = new Vector3(terrainSize.x * xIndex, terrainSize.y, terrainSize.z * yIndex); terrain.name = TrimEnd(terrain.name, "(Clone)") + " [" + xIndex + " , " + yIndex + "]"; terrainTiles.Add(new Vector2(xIndex, yIndex), terrain); GenerateMesh gm = terrain.GetComponent <GenerateMesh>(); gm.TerrainSize = terrainSize; gm.Gradient = gradient; gm.NoiseScale = noiseScale; gm.CellSize = cellSize; gm.NoiseOffset = NoiseOffset(xIndex, yIndex); gm.Generate(); Random.InitState((int)(seed + (long)xIndex * 100 + yIndex));//so it doesn't form a (noticable) pattern of similar tiles PlaceObjects po = gm.GetComponent <PlaceObjects>(); po.TerrainController = this; po.Place(); RandomizeInitState(); return(terrain); }
void OnTriggerExit2D(Collider2D other) { if (other.transform.CompareTag("Player")) { PlaceObjects po = other.gameObject.GetComponent <PlaceObjects>(); //access PlaceObjects script po.UnprepareForSpawning(); } }
void OnTriggerStay2D(Collider2D other) { if (isEnabled && other.transform.CompareTag("Player")) { PlaceObjects po = other.gameObject.GetComponent <PlaceObjects>(); //access PlaceObjects script po.PrepareForSpawning(Optic, transform.parent.position); } }
private void Awake() { place = FindObjectOfType <PlaceObjects>(); tool = FindObjectOfType <MultiTool>(); tileLayout = FindObjectOfType <TileLayout>(); player = GameObject.FindGameObjectWithTag("Player"); indicatorRenderer = indicator.GetComponent <SpriteRenderer>(); }
public void UpdatePlaceObjectScriptParams(GameObject go, bool isRotating, bool placeWrtCorners, bool isCoinOrPlayer, bool scalingRequired, float dynamicWidthForScaling) { PlaceObjects placeObjects = go.GetComponent <PlaceObjects>(); placeObjects.isRotating = isRotating; placeObjects.placeWrtCornors = placeWrtCorners; placeObjects.scalingRequired = scalingRequired; placeObjects.isCoinOrPlayer = isCoinOrPlayer; placeObjects.dynamicWidthForScaling = dynamicWidthForScaling; }
private void Start() { int numCircles = circlePlacement.Count; int numLines = linePlacement.Count; slowmotion = slowMotionGO.GetComponent <Slowmotion>(); for (int i = 0; i < numCircles; i++) { List <Vector3> points = Utils.DrawCircle(circlePlacement[i].xCoordinate, circlePlacement[i].yCoordinate, circlePlacement[i].adjustWrtBorders, circlePlacement[i].radius, circlePlacement[i].circleBorderWidth); int numPoints = points.Count; int assignedIndex = 0; int differenceBetweenIndex = numPoints / circlePlacement[i].count; for (int j = 0; j < circlePlacement[i].count; j++) { GameObject objRevolving = Instantiate(circlePlacement[i].objectType, points[assignedIndex], transform.rotation); objRevolving.name = circlePlacement[i].objectType.name + " on circle"; objRevolving.GetComponentInChildren <Animator>().runtimeAnimatorController = rotateAnimationController; PlaceObjects objectPlacementScript = objRevolving.GetComponent <PlaceObjects>(); objectPlacementScript.isObjectAFreeBird = true; objectPlacementScript.scalingRequired = false; objectPlacementScript.TriggerPlacementOnLine(points, assignedIndex, false); assignedIndex = (assignedIndex + differenceBetweenIndex) % numPoints; slowmotion.gameEntities.Add(objRevolving); } } for (int i = 0; i < numLines; i++) { Vector3 firstPoint = linePlacement[i].firstPoint, secondPoint = linePlacement[i].secondPoint; if (linePlacement[i].placeWrtCorners) { var bottomLeft = mainCamera.ViewportToWorldPoint(new Vector3(0, 0, 0)); var bottomRight = mainCamera.ViewportToWorldPoint(new Vector3(1, 0, 0)); firstPoint.x = bottomLeft.x + cornerOffset; secondPoint.x = bottomRight.x - cornerOffset; } Utils.DrawLine(firstPoint, secondPoint, endPointsSprite); GameObject objMoving = Instantiate(linePlacement[i].objectType, (linePlacement[i].objectSpawnPoint == 0) ? firstPoint : secondPoint, transform.rotation); objMoving.GetComponentInChildren <Animator>().runtimeAnimatorController = rotateAnimationController; objMoving.name = linePlacement[i].objectType.name + " on line"; PlaceObjects objectPlacementScript = objMoving.GetComponent <PlaceObjects>(); objectPlacementScript.isObjectAFreeBird = true; objectPlacementScript.scalingRequired = false; objectPlacementScript.leftRightOffset = 0f; objectPlacementScript.TriggerPlacementOnLine(new List <Vector3>() { firstPoint, secondPoint }, linePlacement[i].objectSpawnPoint, true); slowmotion.gameEntities.Add(objMoving); } }
void OnTriggerExit2D(Collider2D other) { if (other.transform.CompareTag("Player")) { PlaceObjects po = other.gameObject.GetComponent <PlaceObjects>(); if (po.GetState() == "Standard") { po.RemoveCarryInRange(); } } }
// Start is called before the first frame update void Awake() { PlaceObjects place = FindObjectOfType <PlaceObjects>(); tiles = new ObjectTile[tileCountX, tileCountY]; for (int i = 0; i < tileCountX; i++) { for (int j = 0; j < tileCountY; j++) { tiles[i, j] = new ObjectTile(); } } }
// Use this for initialization void Start() { //The mesh data is retained in the SpatialUnderstanding GameObject's coordinate system //This means that the Placement results will be returned in that coordinate system //Thus, we position the clues based on that coordinate system. mAdopt = GameObject.Find("SpatialUnderstanding"); //this is used for communication between WrapClues and PlaceObjects. //this is also one of the reasons why WrapClues needs to be on the same object as PlaceObjects. //if you think the condition above is inconvenient, feel free to pass the PlaceObjects to mPO in some other way //and also check the selfdestruct function mPO = this.gameObject.GetComponent <PlaceObjects>(); }
// Returns boolean for whether the item should be deleted or not public bool Use() { hunger = GameObject.Find("Hunger"); thirst = GameObject.Find("Thirst"); bool toBeDeleted = false; switch (type) { case ItemType.COOKEDGUPPY: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.15f); break; case ItemType.COOKEDTROUT: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.30f); break; case ItemType.COOKEDSALMON: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.40f); break; case ItemType.SUSHI: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.45f); thirst.GetComponent <BarScript>().increment(0.1f); break; case ItemType.RAWGUPPY: toBeDeleted = true; thirst.GetComponent <BarScript>().increment(0.05f); break; case ItemType.RAWTROUT: toBeDeleted = true; thirst.GetComponent <BarScript>().increment(0.05f); break; case ItemType.RAWSALMON: toBeDeleted = true; thirst.GetComponent <BarScript>().increment(0.05f); break; case ItemType.CARROT: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.1f); break; case ItemType.ROASTEDCARROT: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.2f); break; case ItemType.POTATO: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.2f); break; case ItemType.BAKEDPOTATO: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.35f); break; case ItemType.STRAWBERRIES: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.3f); break; case ItemType.PINEAPPLE: toBeDeleted = true; hunger.GetComponent <BarScript>().increment(0.3f); thirst.GetComponent <BarScript>().increment(0.1f); break; case ItemType.FIREPREP: isSwimming = GameObject.Find("Player").GetComponent <Player> ().isSwimming; if (!isSwimming) { toBeDeleted = true; builder = GameObject.Find("Main Camera").GetComponent <PlaceObjects>(); builder.build("Fire", "PlaceFire"); } break; case ItemType.HOE: isSwimming = GameObject.Find("Player").GetComponent <Player> ().isSwimming; if (!isSwimming) { builder = GameObject.Find("Main Camera").GetComponent <PlaceObjects>(); builder.build("Farm", "PlaceFarm"); durability--; if (durability == 0) { toBeDeleted = true; } } break; case ItemType.FRESHWATER: thirst.GetComponent <BarScript>().increment(0.3f); slot.DestroyItem(); newItem = Instantiate(Resources.Load <GameObject>("Bucket").GetComponent <Item>(), slot.transform); colliderBox = newItem.gameObject.GetComponent <BoxCollider2D>(); if (colliderBox != null) { colliderBox.enabled = false; } newItem.transform.position = new Vector3(0, 20f, 0); newItem.GetComponent <SpriteRenderer>().enabled = false; slot.AddItem(newItem); break; case ItemType.SALTWATER: slot.DestroyItem(); newItem = Instantiate(Resources.Load <GameObject>("Bucket").GetComponent <Item>(), slot.transform); colliderBox = newItem.gameObject.GetComponent <BoxCollider2D>(); if (colliderBox != null) { colliderBox.enabled = false; } newItem.transform.position = new Vector3(0, 20f, 0); newItem.GetComponent <SpriteRenderer>().enabled = false; slot.AddItem(newItem); break; case ItemType.WATERPURIFIER: isSwimming = GameObject.Find("Player").GetComponent <Player> ().isSwimming; if (!isSwimming) { toBeDeleted = true; builder = GameObject.Find("Main Camera").GetComponent <PlaceObjects>(); builder.build("WaterPurifier", "PlaceWater"); } break; case ItemType.BARREL: isSwimming = GameObject.Find("Player").GetComponent <Player> ().isSwimming; if (!isSwimming) { toBeDeleted = true; builder = GameObject.Find("Main Camera").GetComponent <PlaceObjects>(); builder.build("Barrel", "PlaceBarrel"); } break; case ItemType.BUCKET: bool nearWater = GameObject.Find("Player").GetComponent <Player> ().switchSwimMode; if (nearWater) { slot.DestroyItem(); newItem = Instantiate(Resources.Load <GameObject>("SaltWater").GetComponent <Item>(), slot.transform); colliderBox = newItem.gameObject.GetComponent <BoxCollider2D>(); if (colliderBox != null) { colliderBox.enabled = false; } newItem.transform.position = new Vector3(0, 20f, 0); newItem.GetComponent <SpriteRenderer>().enabled = false; slot.AddItem(newItem); } break; case ItemType.BOTTLE: toBeDeleted = false; GameObject canvas = GameObject.Find("Canvas"); if (scroll == null) { scroll = Instantiate(Resources.Load <GameObject> (message), canvas.transform); scroll.transform.localPosition = new Vector3(0, 0); } break; } return(toBeDeleted); }