Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Clockwork Wolf on September 02, 2013, 10:32:21 PM
-
Hello!
I am trying to call the public function, damage() in the script below, however SendMessage action takes only one parameter, and I think InvokeMethod action does not even allow parameters (NOTE: PM says it is fine, but errors in the unity console)?
using UnityEngine;
using System.Collections;
public class PAClass : MonoBehaviour {
public int HP = 100;
public float multDark = 0.75f;
public float multLight = 0.25f;
public void damage(int damageDark, int damageLight)
{
float currentDamage = ((float)damageDark * multDark) + ((float)damageLight * multLight);
HP -= (int)Mathf.Floor(currentDamage);
print ("Damaged by: " + currentDamage);
if (HP <= 0)
{
print ("I am dead!");
Destroy(this.gameObject);
}
}
public void testDamage(int damage)
{
HP -= damage;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
There is another function, testDamage in the code that works fine with the SendMessage action. Do I need to create a custom action perhaps?
Thanks!
-
.... the custom action seems to be the way to go!
using System.Collections;
namespace HutongGames.PlayMaker.Actions
{
public class customPMAction : FsmStateAction
{
public FsmGameObject gameObject;
public int lightDamage = 20;
public int darkDamage = 20;
// Use this for initialization
public override void OnEnter () {
if (gameObject.Value!= null)
{
gameObject.Value.GetComponent<PAClass>().damage(darkDamage,lightDamage);
}
Finish();
}
// Update is called once per frame
public override void OnUpdate () {
}
}
}
Sorry for the bother!
-
Dear Clockwork Wolf,
No matter if you could find it out yourself or not, I think this is a valid possibility of making Playmaker even better. I think passing multiple variables through Send Message would be a great help to have.
-
There's a new Call Method action in 1.7.3:
https://hutonggames.fogbugz.com/default.asp?W1139
More documentation and tutorial videos coming soon...