Forked from anonymous/gist:0d299f083c56b00d5aea403f6aae6b22
Last active
April 24, 2017 14:42
-
-
Save CrandellWS/4c93ab5982b00ac1db0581dd75e9807e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Networking; | |
public class YourClass : Player | |
{ | |
[Client] | |
public void Addthing() | |
{ | |
if (Input.GetMouseButtonDown (0)) { | |
var rayS = Camera.main.ScreenPointToRay (Input.mousePosition); | |
RaycastHit hitS; | |
if (Physics.Raycast (rayS, out hitS)) { | |
// valid target? | |
var Kiste = hitS.collider.gameObject.tag == "Sammelbar"; //Sammelbar means gatherable | |
if (Vector3.Distance (GameObject.FindWithTag ("Player").transform.position, hitS.transform.position) >= 4) | |
return; | |
if (Kiste) { | |
ItemTemplate gatherItem = ItemTemplate.dict["Biomasse"]; | |
if (gatherItem != null) | |
{ | |
var freeIdx = inventory.FindIndex(item => !item.valid); | |
if (freeIdx != -1) | |
{ | |
switch (Random.Range (0, 3)) { | |
case 0: | |
CmdAddthing ("Notiz1"); | |
break; | |
case 1: | |
CmdAddthing ("Biomasse"); | |
break; | |
case 2: | |
CmdAddthing ("Notiz2"); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
[Command(channel = Channels.DefaultUnreliable)] // unimportant => unreliable | |
void CmdAddthing(string gatherName) | |
{ | |
ItemTemplate gatherItem = ItemTemplate.dict[gatherName]; | |
if (gatherItem != null) | |
{ | |
InventoryAddAmount(gatherItem, 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment