playMaker

Author Topic: Accessing script in a custom script: using gameobject variable [SOLVED]  (Read 3357 times)

Sly

  • Full Member
  • ***
  • Posts: 127
Hello,

I need help for a custom action. This action is a custom one about accessing script in a custom script:
https://hutonggames.fogbugz.com/default.asp?W540

I just want to know how to change it for having the possibility to to set the owner of this action/and/or any gameobject, any gameobject variable (like in any normal playmaker action). Usually I know how to do that but for this case it's different.

I was thinking about Jean to help me  ::) but if anyone knows how to do that, it could be appreciated!

Thanks in advanced!
« Last Edit: December 03, 2014, 08:30:59 AM by Sly »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Accessing script in a custom script: using gameobject variable
« Reply #1 on: December 02, 2014, 09:12:13 AM »


Code: [Select]
[RequiredField]
[Tooltip("The GameObject to add the script to.")]
public FsmOwnerDefault gameObject;

Sly

  • Full Member
  • ***
  • Posts: 127
Re: Accessing script in a custom script: using gameobject variable
« Reply #2 on: December 02, 2014, 11:52:44 AM »
Hello,
Yes, I know the type of variable I need to use. the problem is in my code I need to change it regarding what we have. The script is accessing the component script so it's a little tricky. I'm posting the code:

This is the component script:
Code: [Select]
using UnityEngine;

public class MyBehavior : MonoBehaviour
{
public float testFloat;
}

There is my custom action:
Code: [Select]
using HutongGames.PlayMaker;

namespace MyNameSpace.Actions
{
[ActionCategory(ActionCategory.ScriptControl)]
[Tooltip("Shows how to interface with a behavior on a game object")]
public class MyBehaviorAction : FsmStateAction
{
public MyBehavior myBehavior;
[UIHint(UIHint.Variable)]
public FsmFloat getTestFloat;

public override void OnUpdate()
{
getTestFloat.Value = myBehavior.testFloat;
}
}
}


I need to have the possibility to set myBehavior variable as a FsmOwnerDefault gameObject. But I don't know how to do that because this value access to the component script.

How I can do that?
« Last Edit: December 02, 2014, 12:04:41 PM by Sly »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Accessing script in a custom script: using gameobject variable
« Reply #3 on: December 02, 2014, 03:09:06 PM »
Code: [Select]
[Tooltip("Target GameObject.")]
public FsmOwnerDefault targetGameObject;

[UIHint(UIHint.Variable)]
public FsmFloat storeTestFloat;

public override void OnUpdate()
{
var go = Fsm.GetOwnerDefaultTarget(targetGameObject);
Component script = go.GetComponent<myBehavior>();
storeTestFloat.Value = script.testFloat;

}

something like that.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 127
Re: Accessing script in a custom script: using gameobject variable
« Reply #4 on: December 02, 2014, 09:06:14 PM »
Hey Lane,
I try your code but I have a couple of error. It's possibly me who missing something. Can you post your entire code (with the beginning) please? It will be very appreciated :)

For now thanks for your help!

Sly

  • Full Member
  • ***
  • Posts: 127
Re: Accessing script in a custom script: using gameobject variable [SOLVED]
« Reply #5 on: December 03, 2014, 08:30:36 AM »
Yo,

Ok I've got it!
There is the code. I just modify some stuff in your code for make it work:
Code: [Select]
using UnityEngine;
using System.Collections;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[Tooltip("Test")]
public class MyBehaviorAction : FsmStateAction
{
[Tooltip("Target GameObject.")]
public FsmOwnerDefault targetGameObject;
//public FsmFloat getTestFloat;
private MyBehavior myBehavior;

[UIHint(UIHint.Variable)]
public FsmFloat storeTestFloat;

public override void OnUpdate()
{
//getTestFloat.Value = myBehavior.testFloat;
var go = Fsm.GetOwnerDefaultTarget(targetGameObject);
myBehavior = go.GetComponent<MyBehavior>();
storeTestFloat.Value = myBehavior.testFloat;

}

}
}

So I can set any gameobject in my variable, but this one needs to have the script MyBehavior attach to him.
Thanks for your help everyone!