Created
June 30, 2014 11:58
-
-
Save kevinruscoe/78fd1869b08b5d04d5a9 to your computer and use it in GitHub Desktop.
A simple trade system for UFPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SimpleTrade : MonoBehaviour { | |
public vp_Inventory inventory; | |
public vp_UnitType required_item; | |
public vp_ItemType given_item; | |
void OnTriggerEnter( Collider col ){ | |
if( col.gameObject.tag == "Player" ){ | |
if( inventory == null ){ | |
inventory = col.gameObject.GetComponent<vp_Inventory>(); | |
} | |
if( inventory.HaveInternalUnitBank( required_item ) ){ | |
if( inventory.GetUnitCount( required_item ) > 0 ){ | |
inventory.TryRemoveUnits( required_item, 1 ); | |
inventory.TryGiveItem( given_item, 1 ); | |
Debug.Log( "Thank you for the " + required_item.DisplayName + ", I have given you " + given_item.IndefiniteArticle + " " + given_item.DisplayName ); | |
}else{ | |
Debug.Log( "You have no " + required_item.DisplayName + "s. :(" ); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment