void MoveObject(pentagon sourceTile, pentagon targetTile, float offset = -0.1f) { GameObject s = sourceTile.GetOccupier(); // move transform s.transform.position = (targetTile.GetTile().transform.position); s.transform.SetParent(targetTile.GetTile().transform); s.transform.rotation = targetTile.GetTile().transform.rotation; s.transform.eulerAngles += new Vector3(0, 0, 180); s.transform.Translate(Vector3.forward * offset); // do tile handling sourceTile.SetOccupier(null); targetTile.SetOccupier(s); sourceTile.SetOccupied(false); targetTile.SetOccupied(true); }
bool MovePlayerObject(int targetTile, float offset = -0.1f, bool attackOnly = false) { bool validMove = true; bool waiting = false; pentagon p = pentagons[targetTile - 1]; if (p.GetOccupied()) { validMove = false; // attack and destroy opponent if it can be destroyed GameObject o = p.GetOccupier(); // Check tile status // blanks can come on blanks try { // pickup gold if (o.transform.tag == "GoldPiece") { gold += 1; validMove = true; p.SetOccupier(null); allOpponents.Remove(o); Destroy(o, 0.1f); Log("You pick up some gold."); } else if (o.transform.tag == "BlackToad") { if (p.GetState() == 0) { validMove = true; p.SetOccupier(null); p.SetState(1); toads.Remove(o); allOpponents.Remove(o); Destroy(o, 0.1f); // colour the tile black SetPentagonColour(Color.black, p.GetTile()); Log("You stomp on the wretched black little thing and smush it to pieces."); } else { Log("You cannot best the toad there"); } } else if (o.transform.tag == "WhiteEagle") { if (p.GetState() == 1) { validMove = true; p.SetOccupier(null); p.SetState(2); allOpponents.Remove(o); eagles.Remove(o); Destroy(o, 0.1f); // colour the tile bright white SetPentagonColour(Color.white, p.GetTile()); } else { Log("You cannot trap the eagle on that side."); } } else if (o.transform.tag == "GreenLion") { if (p.GetState() == 2) { validMove = true; p.SetOccupier(null); p.SetState(3); allOpponents.Remove(o); lions.Remove(o); Destroy(o, 0.1f); // colour the tile green SetPentagonColour(Color.green, p.GetTile()); } else { Log("The lion will yield only when stood upon a white base."); } } else if (o.transform.tag == "RedPelican") { if (p.GetState() == 3) { validMove = true; p.SetOccupier(null); p.SetState(4); allOpponents.Remove(o); pelicans.Remove(o); Destroy(o, 0.1f); // colour the tile golden SetPentagonColour(Color.yellow, p.GetTile()); // Player gets gold Log("The pelican left behind some gold. You pick it up."); Log("This face is shining bright."); gold += 2; GameObject.Find("Gold").GetComponent <Text>().text = "Gold " + gold.ToString(); } else { Log("The pelican needs to be on a green tile to be tamed."); } } // staying still else if (p.GetOccupier() == playerObject) { Log("You stand still."); validMove = true; waiting = true; } else { // if the opponent isn't standing on a proper tile then you can't move there Debug.Log("Can't move there, wrong tile and opponent combination"); validMove = false; } } catch { Debug.Log("Couldn't access tile occupier"); validMove = false; } } if (validMove) { pentagon source = null; foreach (pentagon p2 in pentagons) { if (p2.GetOccupier() == playerObject) { source = p2; } } if (!attackOnly) { MoveObject(source, p); } else { if (!waiting) { GameObject FX = Instantiate(sprayEffect, p.GetTile().transform); FX.transform.position = p.GetTile().transform.position; FX.transform.LookAt(-GameObject.Find("Dodecahedron").transform.position); Destroy(FX, 2.0f); } } /* playerObject.transform.position = (p.GetTile().transform.position); * playerObject.transform.SetParent(p.GetTile().transform); * playerObject.transform.rotation = p.GetTile().transform.rotation; * playerObject.transform.eulerAngles += new Vector3(0, 0, 180); * playerObject.transform.Translate(Vector3.forward * offset); * // remove player from current tile and move them to the next tile in the pentagon list * foreach(pentagon p2 in pentagons) * { * if(p2.GetOccupier() == playerObject) * { * p2.SetOccupier(null); * Debug.Log("Setting player to tile index " + p.GetIndex()); * * p.SetOccupier(playerObject); * } * } */ } return(validMove); }