Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Networking;
  3.  
  4. public class YourClass : Player
  5. {
  6. [Client]
  7. public void Addthing()
  8. {
  9. if (Input.GetMouseButtonDown (0)) {
  10. var rayS = Camera.main.ScreenPointToRay (Input.mousePosition);
  11. RaycastHit hitS;
  12. if (Physics.Raycast (rayS, out hitS)) {
  13. // valid target?
  14. var Kiste = hitS.collider.gameObject.tag == "Sammelbar"; //Sammelbar means gatherable
  15.  
  16. if (Vector3.Distance (GameObject.FindWithTag ("Player").transform.position, hitS.transform.position) >= 4)
  17. return;
  18.  
  19. if (Kiste) {
  20.  
  21. ItemTemplate gatherItem = ItemTemplate.dict["Biomasse"];
  22. if (gatherItem != null)
  23. {
  24. var freeIdx = inventory.FindIndex(item => !item.valid);
  25. if (freeIdx != -1)
  26. {
  27. switch (Random.Range (0, 3)) {
  28. case 0:
  29. CmdAddthing ("Notiz1");
  30. break;
  31. case 1:
  32. CmdAddthing ("Biomasse");
  33. break;
  34. case 2:
  35. CmdAddthing ("Notiz2");
  36. break;
  37. }
  38.  
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. [Command(channel = Channels.DefaultUnreliable)] // unimportant => unreliable
  46. void CmdAddthing(string gatherName)
  47. {
  48. ItemTemplate gatherItem = ItemTemplate.dict[gatherName];
  49. if (gatherItem != null)
  50. {
  51. InventoryAddAmount(gatherItem, 1);
  52.  
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement