Skip to content

Instantly share code, notes, and snippets.

@AndrewWeston9
Created October 6, 2017 06:58
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/826345e15968ff517bb6d2a507861d31 to your computer and use it in GitHub Desktop.
Save AndrewWeston9/826345e15968ff517bb6d2a507861d31 to your computer and use it in GitHub Desktop.
PlayerMove.cs Snippet: Flag placing and removal checks and sending of network messages for flag related functions.
if(Input.GetKey(KeyCode.E) && playerFlagPlaced == true)
{
/*if(Physics.Raycast(ray, out hit, 50))
{
pickup = true;
}
}
else
{
pickup = false;*/
if (checkFlagRange())
{
removeFlag ();
}
}
public void removeFlag()
{
inTrigger = false;
PlayerFlagMessage m = new PlayerFlagMessage ();
m.position = flagShortest.transform.position;
NetworkManager.singleton.client.Send (LevelMsgType.PlayerFlagRequest, m);
}
// Returns true if a flag is within range.
public bool checkFlagRange()
{
if (flagTimer < 1)
{
GameObject[] flagList = GameObject.FindGameObjectsWithTag ("Flag");
float distanceShortest = 1000;
foreach (GameObject flag in flagList) {
float distance = Vector3.Distance (flag.transform.position, this.transform.position);
if (distance < distanceShortest) {
distanceShortest = distance;
flagShortest = flag;
}
}
if (distanceShortest < 3.5f)
{
checkFlagRangeLast = true;
return true;
flagTimer = 30;
}
flagTimer = 30;
checkFlagRangeLast = false;
return false;
}
else
{
return checkFlagRangeLast;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment