Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement