How to pass the variable of a current state machine behavior
I have a state machine behavior that instantiates some particle effects. I then set a trigger through a simple coded input via mono behavior to activate it. This works fine. Now i want to set a public GameObject in the same state machine behavior script which is setup on multiple states so that each script has a different GameObject that is spawned. The problem is when i call that GameObject in the input script (monobehavior) it seemly sets ALL of the GameObjects to the same object. I'm simply declaring the GameObject in state machine behavior so that setting up a new "spell" can be handled entirely in the state machine behavior. Any help would be appreciated. I tried to remove the non-relevent code from the state machine behavior script for clarification.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpellSystemInput : MonoBehaviour {
public Transform MagicSpawnPoint;
Animator anime;
private MagicAttackBehavior xSMB;
public GameObject SpellInd;
public GameObject SpellInd2;
// Use this for initialization
void Start () {
anime = GetComponent<Animator> ();
xSMB = anime.GetBehaviour<MagicAttackBehavior> ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("f1")) {
Debug.Log ("F1 is held down");
SpellInd = Instantiate (exampleSMB.SpellIndicator, MagicSpawnPoint.transform);
}
if (Input.GetKeyUp ("f1")) {
Debug.Log ("F1 is held up");
anime.SetTrigger ("MagicAttack1");
Destroy (SpellInd);
}
if (Input.GetKeyDown ("f2")) {
Debug.Log ("F1 is held down");
SpellInd2 = Instantiate (exampleSMB.SpellIndicator, MagicSpawnPoint.transform);
}
if (Input.GetKeyUp ("f2")) {
Debug.Log ("F1 is held up");
anime.SetTrigger ("MagicAttack2");
Destroy (SpellInd2);
}
}
}
public class MagicAttackBehavior : StateMachineBehaviour { public GameObject SpellIndicator;}
Your answer
