Baserfaz

Change items..

Oct 10th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.76 KB | None | 0 0
  1. public void switchItemSlots(int index) {
  2.         if(inventorySlots.Count > index) {
  3.             if(switchRightHandItem) { //if it's right hands turn
  4.                 if(inventorySlots.IndexOf(currentItemRight) != index) { //if the chosen slot is different than our current item's slot.
  5.                     if(currentItemLeft == null) { //if there is nothing on the left hand
  6.                         if(currentItemRight != null) {
  7.                             currentItemRight.SetActive(false);
  8.                         }
  9.                         inventorySlots[index].SetActive(true);
  10.                         setCurrentItemRight(inventorySlots[index]);
  11.                         invGui.ChangeHighlight(currentItemRight);
  12.                         currentItemRight.GetComponent<Rigidbody> ().useGravity = false;
  13.                         foreach (BoxCollider col in currentItemRight.GetComponentsInChildren<BoxCollider>()) {
  14.                             col.enabled = false;
  15.                         }
  16.                     } else { //if left hand has something
  17.                         if(inventorySlots.IndexOf(currentItemLeft) != index) {
  18.                             if(currentItemRight != null) {
  19.                                 currentItemRight.SetActive(false);
  20.                             }
  21.                             inventorySlots[index].SetActive(true);
  22.                             setCurrentItemRight(inventorySlots[index]);
  23.                             invGui.ChangeHighlight(currentItemRight);
  24.                             currentItemRight.GetComponent<Rigidbody> ().useGravity = false;
  25.                             foreach (BoxCollider col in currentItemRight.GetComponentsInChildren<BoxCollider>()) {
  26.                                 col.enabled = false;
  27.                             }
  28.                         } else {
  29.                             tempSlot = currentItemLeft;
  30.                             currentItemLeft = currentItemRight;
  31.                             currentItemRight = tempSlot;
  32.                         }
  33.                     }
  34.                 } else { //if player tries to change current weapon to a same weapon (same slot) and has only one equipped.
  35.                     if(currentItemLeft == null) {
  36.                         currentItemLeft = currentItemRight;
  37.                         currentItemLeft.SetActive(true);
  38.                         currentItemRight = null;
  39.                     } else { //if player tries to change current weapon to a same weapon (same slot) and has both hands full.
  40.                         tempSlot = currentItemLeft;
  41.                         currentItemLeft = currentItemRight;
  42.                         currentItemRight = tempSlot;
  43.                     }
  44.                 }
  45.                 switchRightHandItem = false;
  46.    
  47.             } else if(!switchRightHandItem) {
  48.                 if(inventorySlots.IndexOf(currentItemLeft) != index) {
  49.                     if(currentItemRight == null) { //if there is nothing on the right hand
  50.                         if(currentItemLeft != null) {
  51.                             currentItemLeft.SetActive(false);
  52.                         }
  53.                         inventorySlots[index].SetActive(true);
  54.                         setCurrentItemLeft(inventorySlots[index]);
  55.                         invGui.ChangeHighlight(currentItemLeft);
  56.                         currentItemLeft.GetComponent<Rigidbody> ().useGravity = false;
  57.                         foreach (BoxCollider col in currentItemLeft.GetComponentsInChildren<BoxCollider>()) {
  58.                             col.enabled = false;
  59.                         }
  60.                     } else {
  61.                         if(inventorySlots.IndexOf(currentItemRight) != index) {
  62.                             if(currentItemLeft != null) {
  63.                                 currentItemLeft.SetActive(false);
  64.                             }
  65.                             inventorySlots[index].SetActive(true);
  66.                             setCurrentItemLeft(inventorySlots[index]);
  67.                             invGui.ChangeHighlight(currentItemLeft);
  68.                             currentItemLeft.GetComponent<Rigidbody> ().useGravity = false;
  69.                             foreach (BoxCollider col in currentItemLeft.GetComponentsInChildren<BoxCollider>()) {
  70.                                 col.enabled = false;
  71.                             }
  72.                         } else {
  73.                             tempSlot = currentItemLeft;
  74.                             currentItemLeft = currentItemRight;
  75.                             currentItemRight = tempSlot;
  76.                         }
  77.                     }
  78.                 } else { //if player tries to change current weapon to a same weapon (same slot) and has only one equipped.
  79.                     if(currentItemRight == null) {
  80.                         currentItemRight = currentItemLeft;
  81.                         currentItemRight.SetActive(true);
  82.                         currentItemLeft = null;
  83.                     } else { //if player tries to change current weapon to a same weapon (same slot) and has both hands full.
  84.                         tempSlot = currentItemLeft;
  85.                         currentItemLeft = currentItemRight;
  86.                         currentItemRight = tempSlot;
  87.                     }
  88.                 }
  89.                 switchRightHandItem = true;
  90.             }
  91.         }
  92.     }
Advertisement
Add Comment
Please, Sign In to add comment