Grannyboy
Active member
I got some cool sword slash vfx laying around that I want to use with my melee weapon. The trail system dosent really work at all with spawning specific particle systems so I made this script with help from @ChristianWiele!
This is very basic but its very easy to build upon. The concept works around the animator audio part of the melee weapon script. More on combo set ups etc is in the tutorial on melee weapons from Opsive:
First of all set a state name and a empty state with that name in the melee script:
Then add a new script on your character:
In the script put the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Items.Actions;
public class StartSwordSlash_G : MonoBehaviour
{
[SerializeField] private ParticleSystem swordSlashOneParticle;
public void Awake()
{
EventHandler.RegisterEvent<GameObject, string, bool> ("OnStateChange", OnStateChange);
}
private void OnStateChange(GameObject gameObject, string stateName, bool active)
{
if (stateName == "SwordSlashOne" && active)
{
Debug.Log("SwordSlash one initiated");
swordSlashOneParticle.Play();
}
}
public void OnDestroy()
{
EventHandler.RegisterEvent<GameObject, string, bool>("OnStateChange", OnStateChange);
}
}
(Please tell me how to write to get the above code into a code box)
I have my VFX placed as a child of my character, but place it where ever suits your VFX best.
Result:
This is very basic but its very easy to build upon. The concept works around the animator audio part of the melee weapon script. More on combo set ups etc is in the tutorial on melee weapons from Opsive:
First of all set a state name and a empty state with that name in the melee script:
Then add a new script on your character:
In the script put the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Items.Actions;
public class StartSwordSlash_G : MonoBehaviour
{
[SerializeField] private ParticleSystem swordSlashOneParticle;
public void Awake()
{
EventHandler.RegisterEvent<GameObject, string, bool> ("OnStateChange", OnStateChange);
}
private void OnStateChange(GameObject gameObject, string stateName, bool active)
{
if (stateName == "SwordSlashOne" && active)
{
Debug.Log("SwordSlash one initiated");
swordSlashOneParticle.Play();
}
}
public void OnDestroy()
{
EventHandler.RegisterEvent<GameObject, string, bool>("OnStateChange", OnStateChange);
}
}
(Please tell me how to write to get the above code into a code box)
I have my VFX placed as a child of my character, but place it where ever suits your VFX best.
Result: