Skip to content

Instantly share code, notes, and snippets.

@AndrewWeston9
Last active October 6, 2017 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewWeston9/725f332200b5ba15b57297fcee46d2c3 to your computer and use it in GitHub Desktop.
Save AndrewWeston9/725f332200b5ba15b57297fcee46d2c3 to your computer and use it in GitHub Desktop.
PlayerMove.cs Snippet: Placing a block in the world.
if (Input.GetKeyDown(KeyCode.LeftControl) && (isGrounded () || attached))
{
if (playerFlagPlaced == false || currentBlockType != 10)
{
if(!checkFlagRange() && (checkResource() || currentBlockType == 10 || currentBlockType == 1))
{
int px = (int)(playerpos.x + 0.5f);
int py = Math.Max ((int)(playerpos.y), (int)WorldManager.minLevelHeight);
int pz = (int)(playerpos.z + 0.5f);
Debug.Log ("place at " + px + " " + pz + " " + py);
if (attached) {
localWorld.placeBlock (px, pz, py, currentBlockType);
} else {
localWorld.placeBlock (px, pz, py + 1.0f, currentBlockType);
}
//Quest Manager log
QuestManager.qManager.AddQItem ("Place a block", 1);
y = 0.2f;
if (currentBlockType == 10) {
playerFlagPlaced = true;
transform.Translate (0, 3.0f, 0);
//Quest Manager log
QuestManager.qManager.AddQItem ("Place a flag", 1);
} else {
transform.Translate (0, 1.5f, 0);
}
adjustResource();
attached = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment