playMaker

Author Topic: Heath action  (Read 5037 times)

Robert Foster

  • Playmaker Newbie
  • *
  • Posts: 36
Heath action
« on: January 16, 2012, 06:28:55 PM »
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions{

[ActionCategory(ActionCategory.GUIElement)]
[Tooltip("get Heath")]
public class HeathAction : FsmStateAction
{
[RequiredField]
public GUITexture heathGuI;
public FsmFloat  healthGUIWidth;
public FsmFloat gotHitTimer;
public FsmFloat maximumHitPoints;
public FsmFloat hitPoints;
   

public override void Reset()
{
heathGuI = null;
healthGUIWidth = null;
gotHitTimer = -1.0f;
maximumHitPoints = 100f;
hitPoints = 100f;

}

     public override void OnEnter()
{

OnGUI();



}


public override void OnGUI()
{




}

   }

}


« Last Edit: January 16, 2012, 06:30:42 PM by lorddarkness »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Heath action
« Reply #1 on: January 17, 2012, 06:32:33 AM »
Hi,

 The action does nothing, can you explain? :) Maybe you pasted and attached the wrong action?

Also, I am not sure why you are calling onGUI() within OnEnter() ? despite the fact that onGUI is empty, this is not really how it's meant to be used I think.

 Bye,

 Jean

Robert Foster

  • Playmaker Newbie
  • *
  • Posts: 36
Re: Heath action
« Reply #2 on: January 17, 2012, 09:05:39 PM »
sorry i was testing  but have problem writing the scrpt here the original scrpt
Code: [Select]
ar maximumHitPoints = 100.0;
var hitPoints = 100.0;
var healthGUI : GUITexture;


private var healthGUIWidth = 0.0;
private var gotHitTimer = -1.0;


function Awake () {


healthGUIWidth = healthGUI.pixelInset.width;
}

function ApplyDamage (damage : float) {
if (hitPoints < 0.0)
return;

// Apply damage
hitPoints -= damage;



// Are we dead?
if (hitPoints < 0.0)
Die();
}

function Die () {


// Disable all script behaviours (Essentially deactivating player control)
var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
for (var b in coms) {
var p : MonoBehaviour = b as MonoBehaviour;
if (p)
p.enabled = false;
}

LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
}

function LateUpdate () {
// Update gui every frame
// We do this in late update to make sure machine guns etc. were already executed
UpdateGUI();
}



function UpdateGUI () {
// Update health gui
// The health gui is rendered using a overlay texture which is scaled down based on health
// - Calculate fraction of how much health we have left (0...1)
var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);

// - Adjust maximum pixel inset based on it
healthGUI.pixelInset.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;


}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Heath action
« Reply #3 on: January 18, 2012, 12:59:56 AM »
Hi,

 ok, I think you want to do too much in this action.

 Actions should remain as generic as possible doing something very very specific, so that you can reuse it and apply it in many case, for example as your system evolves, your health system will likely evolve too.

 So:

you should have one fsm responsible for applying damage and injecting the health to the guitexture width.
you then should fire a global event "DIE"
and other fsm could react to this "DIE" event

for example, the player control would have a fsm that receive this "DIE" event and stop working
then another fsm would be responsible to fade and load levels.

This way, if you have a problem you can better analyze and find the issue,

I would start by creating a custom action that can map an int ( as a percentage for example) to the width of a guiTexture. That's a good action actually. The the rest would be done with existing actions within their respective fsm.

Bye,

 Jean