private void Start() { AnchorType = Resources.Load("Prefabs/Bracket") as GameObject; // ameObject.CreatePrimitive(PrimitiveType.Cube); float treeHeight = 0.0f; foreach (var t in Trees) { treeHeight += t.transform.position.y; } treeHeight = treeHeight / 3.0f; foreach (var t in Trees) { TreeAnchor ta = t.gameObject.AddComponent <TreeAnchor>(); GameObject anchor = Instantiate(AnchorType); ta.Anchor = anchor; //anchor.transform.position = t.transform.position + new Vector3(0f, Elevation, 0f); anchor.transform.position = new Vector3(t.transform.position.x, treeHeight, t.transform.position.z); ta.CPTreeOffset = 0.5f; ta.elevation = Elevation; ta.PlateOffset = 0f; ta.diameter = 0.5f; anchor.transform.localScale = new Vector3(ta.diameter, ta.diameter, ta.diameter); ta.Anchor.layer = 8; } UpdateAnchors(); }
public void UpdateAnchors() // Called only when we need to regenerate the Tree House. { NeedRefresh = false; // Reset our flag. OrderTrees(); // Figure out my trees. if (OrderedTrees.Count == 3) { for (int t = 0; t < 3; t++) { GameObject anchor = OrderedTrees[t].GetComponent <TreeAnchor>().Anchor; TreeAnchor ta = OrderedTrees[t].GetComponent <TreeAnchor>(); OrderedTrees[t].transform.position = anchor.transform.position - new Vector3(0, OrderedTrees[t].GetComponent <TreeAnchor>().elevation, 0); if (t == 0) { anchor.transform.LookAt((OrderedTrees[1].GetComponent <TreeAnchor>().Anchor.transform.position + OrderedTrees[2].GetComponent <TreeAnchor>().Anchor.transform.position) / 2); } else if (t == 1) { anchor.transform.LookAt(OrderedTrees[2].GetComponent <TreeAnchor>().Anchor.transform.position); } else if (t == 2) { anchor.transform.LookAt(OrderedTrees[1].GetComponent <TreeAnchor>().Anchor.transform.position); } //OrderedTrees[t].GetComponent<TreeAnchor>().CP = anchor.transform.position + anchor.transform.forward * OrderedTrees[t].GetComponent<TreeAnchor>().CPTreeOffset; OrderedTrees[t].GetComponent <TreeAnchor>().CP = anchor.transform.position; } gameObject.GetComponent <Deck>().DrawDeck(); } }