Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Created June 30, 2014 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinruscoe/78fd1869b08b5d04d5a9 to your computer and use it in GitHub Desktop.
Save kevinruscoe/78fd1869b08b5d04d5a9 to your computer and use it in GitHub Desktop.
A simple trade system for UFPS
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