How to make custom script use UCC's State System & respond to it?

NitinBan55

New member
Hi. We want our custom script to respond to a change in state. Like for example we have created a custom script and inherited it from StateBehavior, and created our custom preset which simply sets a boolean value to true, when the Aim state is active.
Now the problem is that when the Player aims, rest of the scripts that inherit StateBehavior like CameraController and others, set the Aim state active and the values are set respectively. But it doesn't work in our case.

Here's a screenshot for reference.
.Custom State Behavior 01.png
(Basically the Combat Started bool should set to true when the Aim state is active)

This is the Preset Setting:
Custom State Behavior 02.png

Here's the script:
public class GameManager : StateBehavior
{
[SerializeField] private bool combatStarted;
public bool CombatStarted { get { return combatStarted; } set { combatStarted = value ; } }

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{

}
}



When we manually activate the state, then it works perfectly.

Custom State Behavior 03.png
(The Combat Started boolean is set to true as soon as Aim State is active, and is set to false again when Aim in no more active)

We want this to work automatically based upon state change (in this case when Player Aims).
 
Since this is an independent GameObjecty you will need to call StateManager.Link to link the GameObject to the player.
 
Since this is an independent GameObjecty you will need to call StateManager.Link to link the GameObject to the player.
Yes, it worked! Thank you @Justin .

For those who come by this post this is the solution:

// Start is called before the first frame update
void Start()
{
//linkedGameObject - Player, CameraController or any object that activates/triggers the state.
//gameObject - The gameObject this script is attached to it.

StateManager.LinkGameObjects(linkedGameObject, this.gameObject, true);
}
 
Top