void Awake() { gridCollider = _grid.gameObject.GetComponent <Collider>(); // Perform an initial align and snap the objects to the bottom. _grid.AlignTransform(transform); transform.position = CalculateOffsetY(); // Store the first safe position. oldPosition = transform.position; // Setup the rigidbody for collision and construct a trigger. SetupRigidbody(); ConstructTrigger(); }
private void AlignTransform(Transform t, bool rotate) { if (rotate) { t.rotation = GridTransfrom.rotation; } var oldPosition = t.position; if (_rectGrid) { _rectGrid.AlignTransform(t); } else if (_hexGrid) { _hexGrid.AlignTransform(t); } else { throw new System.NullReferenceException("No grid set"); } for (var i = 0; i < 3; ++i) { if (IgnoredAxes[i]) { var newPosition = t.position; newPosition[i] = oldPosition[i]; t.position = newPosition; } } }
void Start() { _grid = ForbiddenTiles._grid; _renderer = _grid.gameObject.GetComponent <Parallelepiped>(); _grid.AlignTransform(transform); }
// Use this for initialization void Start() { if (GameObject.Find("Grid")) { _grid = GameObject.Find("Grid").GetComponent <RectGrid>(); Vector3 position = transform.position; position.x = xPos + 0.5f; position.z = zPos + 0.5f; position.y = yPos + 0.5f; if (respawnMarker) { Helpers.GetTile(xPos, zPos).respawnMarker = true; transform.GetComponent <Renderer>().material.color = Color.blue; } transform.position = position; _grid.AlignTransform(transform); } // Get the mesh Mesh theMesh = this.transform.GetComponent <MeshFilter>().mesh as Mesh; // Now store a local reference for the UVs Vector2[] theUVs = new Vector2[theMesh.uv.Length]; theUVs = theMesh.uv; // set UV co-ordinates //TOP theUVs[4] = new Vector2(.25f, .75f); theUVs[5] = new Vector2(.5f, .75f); theUVs[8] = new Vector2(.25f, 1f); theUVs[9] = new Vector2(.25f, 1f); //FRONT theUVs[2] = new Vector2(0f, .75f); theUVs[3] = new Vector2(.25f, .75f); theUVs[0] = new Vector2(0f, .5f); theUVs[1] = new Vector2(.25f, .5f); //BACK theUVs[10] = new Vector2(0f, .75f); theUVs[11] = new Vector2(.25f, .75f); theUVs[6] = new Vector2(0f, .5f); theUVs[7] = new Vector2(.25f, .5f); //LEFT theUVs[17] = new Vector2(0f, .75f); theUVs[18] = new Vector2(.25f, .75f); theUVs[16] = new Vector2(0f, .5f); theUVs[19] = new Vector2(.25f, .5f); //RIGHT theUVs[22] = new Vector2(0f, .75f); theUVs[21] = new Vector2(.25f, .75f); theUVs[23] = new Vector2(0f, .5f); theUVs[20] = new Vector2(.25f, .5f); //BOTTOM theUVs[15] = new Vector2(.25f, .5f); theUVs[12] = new Vector2(.5f, .5f); theUVs[13] = new Vector2(.25f, .25f); theUVs[14] = new Vector2(.25f, .5f); // Assign the mesh its new UVs theMesh.uv = theUVs; }