Skip to content

Instantly share code, notes, and snippets.

View AndrewWeston9's full-sized avatar

Andrew Weston AndrewWeston9

  • Victoria, Australia
View GitHub Profile
@AndrewWeston9
AndrewWeston9 / PlayerMove.cs
Created October 6, 2017 06:58
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;*/
@AndrewWeston9
AndrewWeston9 / PlayerMove.cs
Created October 6, 2017 06:57
PlayerMove.cs Snippet: Adjustment of currently accessed block type for placing by the player.
/// Change the currentBlockType
if (Input.GetKey (KeyCode.Alpha1))
{
currentBlockType = 1;
}
if (Input.GetKey (KeyCode.Alpha2))
{
currentBlockType = 2;
}
@AndrewWeston9
AndrewWeston9 / PlayerMove.cs
Created October 6, 2017 06:56
PlayerMove.cs Snippet: functions for resource changes, communicating with PlayerState class.
// Current block type selected by the player to be placed.
int currentBlockType = 1;
/// Is the player flag placed in the world.
public bool playerFlagPlaced = false;
bool inTrigger = false;
GameObject flagShortest;
@AndrewWeston9
AndrewWeston9 / PlayerState.cs
Created October 6, 2017 06:48
PlayerState.cs Snippet: Resource system that tracks the amount of resource for the player and controls the gain and reduction in resource.
private bool inTrigger;
private string ResourceName;
private Vector3 ResourcePosition;
PlayerMove pmove;
//GameObject playerObject;
@AndrewWeston9
AndrewWeston9 / LocalWorld.cs
Last active October 6, 2017 09:04
LocalWorld.cs Snippet: Created by another team member, I took their code and changed it to work in a network environment, sending the emotes between clients through the server.
void Start () {
emoteDisplayer = new EmoteDisplayClass();
}
public void displayEmote(int emoteType, NetworkInstanceId netId)
{
emoteDisplayer.displayEmote (emoteType, netId);
}
public class EmoteDisplayClass : ScriptableObject
@AndrewWeston9
AndrewWeston9 / PlayMove.cs
Last active October 6, 2017 09:04
PlayMove.cs Snippet: Camera pause function when GUI is in use. Created by myself and another team member.
bool setUIToFalse = true;
public void SetUIOpenTrue()
{
UIOpen = true;
}
public void SetUIOpenFalse()
{
UIOpen = false;
@AndrewWeston9
AndrewWeston9 / PlayerAnimator.cs
Created October 6, 2017 06:35
Animation controller for the player character. Controls walking and gathering animations.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using System.Collections.Generic;
using System;
public class PlayerAnimator : NetworkBehaviour {
public Animator anim;
public float speed = 2.0f;
@AndrewWeston9
AndrewWeston9 / EmoteWheel.cs
Last active October 6, 2017 09:04
EmoteWheel.cs Snippet: Camera pause function when GUI is in use. Created by myself and another team member.
if(menuon == true)
{
setUIToFalse = false;
PCamera = this.transform.parent.gameObject;
netIDC = PCamera.GetComponent<NetworkIdentity>().netId;
PCamera = ClientScene.FindLocalObject(netIDC);
pmove = PCamera.GetComponent<PlayerMove>();
pmove.SetUIOpenTrue();
}
else if (setUIToFalse == false)
@AndrewWeston9
AndrewWeston9 / EmoteWheel.cs
Last active October 6, 2017 09:04
EmoteWheel.cs Snippet: Created by another team member, I took their code and changed it to work in a network environment, sending the emotes between clients through the server.
public void ButtonAction()
{
buttons[CurMenuItem].sceneimage.color = buttons[CurMenuItem].PressedColor;
GameObject Player = this.transform.parent.gameObject;
NetworkInstanceId netID = Player.GetComponent<NetworkIdentity>().netId;
Debug.Log ("Sending emote with networkID: " + netID.ToString());
Vector3 offset = new Vector3(0.0f, 2.5f, 0.0f);
//IconObject DisplayEmote;
if (CurMenuItem == 0)
{
@AndrewWeston9
AndrewWeston9 / LocalWorld.cs
Last active October 6, 2017 06:41
LocalWorld.cs Snippet: Message handling, client side.
NetworkClient.allClients[0].RegisterHandler (LevelMsgType.EmoteSingleSender, ServerCommandHandler); // Handle incoming emotes from server
NetworkClient.allClients[0].RegisterHandler (LevelMsgType.PlayerFlagRequest, ServerCommandHandler);
case LevelMsgType.EmoteSingleSender:
/// Handle incoming emotes from server
{
SendEmoteMessageAndClientID m = netMsg.ReadMessage<SendEmoteMessageAndClientID> ();
displayEmote(m.emoteType, m.netId);
Debug.Log ("Incoming emote to client from server from network id: " + m.netId);
}