Hey all. So I figured something like a Healing Potion would want more than just a prefab to spawn at the player’s feet and then stay there when you run away. So I made a simple change to the Prefab Spawn Effect. I am actually amazed it worked (So I am waiting for Brian to tell me what bugs I introduced doing this). Now you can tell it to stick the prefab on the user’s transform so it stays with them. I suppose that you could just make a separate prefab spawn effect for this, but it’s just one field and one if statement to adjust the current one. There are PLENTY of abilities that this will be handy for(buffs and MOST self targeted abilities in general):
public class SpawnTargetPrefabEffect : EffectStrategy
{
[Tooltip("Prefab to Spawn.")]
[SerializeField] Transform prefabToSpawn;
[Tooltip("Should the prefab be parented to the user?")]
[SerializeField] bool followUser = false;
[Tooltip("How long before destroying Prefab? (-1 for never).")]
[SerializeField] float destroyDelay = -1;
public override void StartEffect(AbilityData data, Action finished)
{
data.StartCoroutine(Effect(data, finished));
}
private IEnumerator Effect(AbilityData data, Action finished)
{
Transform prefabInstance;
// Spawn prefab on the user if enabled in editor, otherwise spawn at the selected target with no parent.
if (followUser) prefabInstance = Instantiate(prefabToSpawn, data.GetUser().transform);
else
{
prefabInstance = Instantiate(prefabToSpawn);
prefabInstance.position = data.GetTargetedPoint();
}
if(destroyDelay > 0)
{
yield return new WaitForSeconds(destroyDelay);
Destroy(prefabInstance.gameObject);
}
finished();
}
}