//-----------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------

if (!isObject(CountOnDeathBehavior))
{
   %template = new BehaviorTemplate(CountOnDeathBehavior);
   
   %template.friendlyName = "CountOnDeath";
   %template.behaviorType = "Game";
   %template.description  = "When object dies, changes a counter value (settable)";

   %template.addBehaviorField(count, "The number to modify the value by (-ve is ok)", int, 100);
   %template.addBehaviorField(counter, "The counter object", object, "", t2dSceneObject);
}

// basically, when the object this behavior is attached to dies
// this behavior looks at the counter object and tries to modify
// any counter behavior attached to it.

function CountOnDeathBehavior::onRemoveFromScene(%this, %scenegraph)
{
   if (!isObject(%this.counter))
      return;

   %counter = %this.counter.getBehavior("CounterBehavior");
   if (!isObject(%counter))
      return;

   %counter.ModifyCount(%this.count);   
}
