} // end Awake function // Use this for initialisation void Start() { // Initialise the variables. m_resourceList = GetComponent <ResourceList>(); m_allyScript = GetComponent <Ally>(); m_maxWeight = 300; m_maxInventory = 20; m_currency = 0; m_attackPower = 0; m_defencePower = 0; m_bonuses = new List <GameObject>(); } // end Start function
} // end TransferCurrency function // Transfers a resource to another character. public void TransferResource(GameObject other, Resource resource) { // Check if the resource object exists. if (resource == null) { // Simply return. return; } // Get the resource list script attached the other character object. ResourceList otherResourceScript = other.GetComponent <ResourceList>(); // Get the character script attached the other character object. Character otherCharacterScript = other.GetComponent <Character>(); // Get the resource list script attached the character this is attached to. ResourceList charResourceScript = this.gameObject.GetComponent <ResourceList>(); // Check if the script objects exists. if (otherResourceScript == null || charResourceScript == null || otherCharacterScript == null) { print("NULL"); // Simply return. return; } // Check if the other character recieving this resource will put the character overweight. if (otherResourceScript.TotalWeight + resource.WeightValue <= otherCharacterScript.MaxWeight) { // Check if there is enough room for this resource. if (otherResourceScript.TotalSize + resource.SizeValue <= otherCharacterScript.MaxInventory) { // Add the resource to the other character. otherResourceScript.AddResource(resource, 1); // Remove the resource from the character this is attached to. charResourceScript.RemoveResource(resource); } // end if size else { print("Transfer failed. Their max inventory capacity reached."); } // end else size } // end if weight else { print("WEIGHT: " + otherResourceScript.TotalWeight); print("MAX WEIGHT: " + otherCharacterScript.MaxWeight); print("THIS MAX WEIGHT: " + this.MaxWeight); print("ALLY MAX WEIGHT: " + m_allyScript[0].gameObject.GetComponent <Character>().MaxWeight); print("Transfer failed. Their max inventory weight reached."); } // end else weight } // end TransferGold function