|
| 1 | +using System.Collections; |
| 2 | +using System.Collections.Generic; |
| 3 | +using UnityEngine; |
| 4 | + |
| 5 | +public class PlayerCrafting : MonoBehaviour { |
| 6 | + |
| 7 | + bool crafting; |
| 8 | + |
| 9 | + bool bridgeRune, torchRune, axeRune, netRune, shovelRune; |
| 10 | + // Use this for initialization |
| 11 | + void Start () { |
| 12 | + crafting = false; |
| 13 | + bridgeRune = false; |
| 14 | + torchRune = false; |
| 15 | + axeRune = false; |
| 16 | + netRune = false; |
| 17 | + shovelRune = false; |
| 18 | + } |
| 19 | + |
| 20 | + // Update is called once per frame |
| 21 | + void Update () { |
| 22 | + |
| 23 | + GameObject player = GameObject.Find("Player"); |
| 24 | + PlayerMovement inventory = player.GetComponent<PlayerMovement>(); // !!! change me when inventory moves to own script !!! |
| 25 | + |
| 26 | + // check that user is on transmutation circle and which recipe to use |
| 27 | + // crafting for bridge |
| 28 | + if (crafting == true && bridgeRune == true && Input.GetKeyDown(KeyCode.Alpha3)) |
| 29 | + { |
| 30 | + |
| 31 | + // check for necessary materials |
| 32 | + if (inventory.logCount >= 3) |
| 33 | + { |
| 34 | + inventory.logCount -= 3; |
| 35 | + inventory.logDisplay.text = inventory.logCount.ToString(); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + if (crafting == true && torchRune == true && Input.GetKeyDown(KeyCode.Alpha1)) |
| 40 | + { |
| 41 | + |
| 42 | + // check for necessary materials |
| 43 | + if (inventory.logCount >= 1 && inventory.clothCount >= 2) |
| 44 | + { |
| 45 | + inventory.logCount -= 1; |
| 46 | + inventory.clothCount -= 2; |
| 47 | + inventory.logDisplay.text = inventory.logCount.ToString(); |
| 48 | + inventory.clothDisplay.text = inventory.clothCount.ToString(); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + if (crafting == true && axeRune == true && Input.GetKeyDown(KeyCode.Alpha2)) |
| 53 | + { |
| 54 | + |
| 55 | + // check for necessary materials |
| 56 | + if (inventory.logCount >= 1 && inventory.metalCount >= 2) |
| 57 | + { |
| 58 | + inventory.logCount -= 1; |
| 59 | + inventory.metalCount -= 2; |
| 60 | + inventory.logDisplay.text = inventory.logCount.ToString(); |
| 61 | + inventory.metalDisplay.text = inventory.metalCount.ToString(); |
| 62 | + |
| 63 | + inventory.hasAxe = true; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + if (crafting == true && netRune == true && Input.GetKeyDown(KeyCode.Alpha4)) |
| 68 | + { |
| 69 | + |
| 70 | + // check for necessary materials |
| 71 | + if (inventory.logCount >= 2 && inventory.clothCount >= 3) |
| 72 | + { |
| 73 | + inventory.logCount -= 2; |
| 74 | + inventory.clothCount -= 3; |
| 75 | + inventory.logDisplay.text = inventory.logCount.ToString(); |
| 76 | + inventory.clothDisplay.text = inventory.clothCount.ToString(); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + if (crafting == true && shovelRune == true && Input.GetKeyDown(KeyCode.Alpha5)) |
| 81 | + { |
| 82 | + |
| 83 | + // check for necessary materials |
| 84 | + if (inventory.logCount >= 2 && inventory.metalCount >= 3) |
| 85 | + { |
| 86 | + inventory.logCount -= 2; |
| 87 | + inventory.metalCount -= 3; |
| 88 | + inventory.logDisplay.text = inventory.logCount.ToString(); |
| 89 | + inventory.metalDisplay.text = inventory.metalCount.ToString(); |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + private void OnTriggerEnter2D(Collider2D other) |
| 96 | + { |
| 97 | + |
| 98 | + if (other.gameObject.CompareTag("Transmutation")) |
| 99 | + { |
| 100 | + crafting = true; |
| 101 | + }//end Transmutation if |
| 102 | + |
| 103 | + if (other.gameObject.CompareTag("Bridge Rune")) |
| 104 | + { |
| 105 | + bridgeRune = true; |
| 106 | + other.gameObject.SetActive(false); |
| 107 | + } |
| 108 | + |
| 109 | + if(other.gameObject.CompareTag("Torch Rune")) |
| 110 | + { |
| 111 | + torchRune = true; |
| 112 | + other.gameObject.SetActive(false); |
| 113 | + } |
| 114 | + |
| 115 | + if(other.gameObject.CompareTag("Axe Rune")) |
| 116 | + { |
| 117 | + axeRune = true; |
| 118 | + other.gameObject.SetActive(false); |
| 119 | + } |
| 120 | + |
| 121 | + if(other.gameObject.CompareTag("Net Rune")) |
| 122 | + { |
| 123 | + netRune = true; |
| 124 | + other.gameObject.SetActive(false); |
| 125 | + } |
| 126 | + |
| 127 | + if(other.gameObject.CompareTag("Shovel Rune")) |
| 128 | + { |
| 129 | + shovelRune = true; |
| 130 | + other.gameObject.SetActive(false); |
| 131 | + } |
| 132 | + }// end of OnTriggerEnter |
| 133 | + |
| 134 | + private void OnTriggerExit2D(Collider2D other) |
| 135 | + { |
| 136 | + if (other.gameObject.CompareTag("Transmutation")) |
| 137 | + { |
| 138 | + crafting = false; |
| 139 | + }//end Transmutation if |
| 140 | + }// end OnTriggerEnter |
| 141 | +}// end PlayerCrafting |
0 commit comments