Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using UnityEngine.Networking;
public partial class 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
You can’t perform that action at this time.