Pages 1
Universal Fighting Engine Forum We are no longer using the forum to answer questions due to bot attacks. Please use our discord instead: https://discord.gg/hGMZhF7 |
You are not logged in. Please login or register.
Universal Fighting Engine Forum → Source Coding → Destroy character move's particle effect after they get hit
Are you using destroy when move ends in the particle effect settings?
@FreedTerror: I don't use destroy when move ends because the particle doesn't even show up when the move is executed.
Seems like your doing a custom script to handle this then?
Where do I place this script, please? I will try it immediately.
Where do I place this script, please? I will try it immediately.
Place the script onto your character prefab.
I updated the script recently, I recommend using the new version due to the new disable Gameobject option. You will contribute less to the Garbage collecter if you use that option.
@FreedTerror: I added the script in my work and tested it; it didn't work. Nonetheless, I'll keep it in. Perhaps I can build upon it.
Thank you very much!
I did test it myself and it did work. Perhaps you missed something while setting it up?
@FreedTerror: I copied and pasted your script as is; and I added them to the prefabs of my characters.
I'm not using UFE particles. I'm using my own particles.
Did you forget to fill out the required fields?
Here's a video of it working.
https://imgur.com/a/eGiSdzm
@FreedTerror: You're right, I missed the adding the required fields. So you just add the moves, required prefabs, and position?
https://ibb.co/MgLtfk0
@FreedTerror: It works! It's a Christmas Miracle! Thank you very much and Happy Holidays!
Your welcome!
I think I could add an array to the prefabs option, that way you could easily create multiple objects per move.
I'll post a new updated script sometime.
@FreedTerror: Please consider time duration as well.
Here's a version with the timer.
Let me know if you need anything else for it.
Edit: Added an isn't null check to prevent errors.
Edit: This version is up to date.
using UnityEngine;
using UFE3D;
namespace FreedTerror
{
public class UFE2FTEDestroyWhenMoveEnds : MonoBehaviour
{
private ControlsScript myControlsScript;
[System.Serializable]
public class PrefabOptions
{
public MoveInfo move;
public int spawnFrame;
public GameObject prefab;
[HideInInspector]
public GameObject spawnedGameObject;
public bool sticky;
public Vector3 spawnPosition;
public bool mirrorOnRightSide;
public bool destroyWhenMoveEnds;
public bool destroyWhenTimerEnds;
public float destroyDelay;
[HideInInspector]
public float destroyTimer;
[Tooltip("If enabled, the spawned GameObject will be disabled instead of destroyed.")]
public bool disableGameObject;
}
[SerializeField]
private PrefabOptions[] prefabOptions;
// Start is called before the first frame update
void Start()
{
if (myControlsScript == null)
{
myControlsScript = GetComponentInParent<ControlsScript>();
}
}
// Update is called once per frame
void Update()
{
if (myControlsScript == null) return;
int length = prefabOptions.Length;
for (int i = 0; i < length; i++)
{
if (myControlsScript.currentMove != null
&& myControlsScript.currentMove.moveName == prefabOptions[i].move.moveName
&& myControlsScript.currentMove.currentFrame == prefabOptions[i].spawnFrame)
{
if (prefabOptions[i].spawnedGameObject == null)
{
prefabOptions[i].spawnedGameObject = Instantiate(prefabOptions[i].prefab);
prefabOptions[i].destroyTimer = prefabOptions[i].destroyDelay;
}
else
{
prefabOptions[i].spawnedGameObject.SetActive(true);
prefabOptions[i].destroyTimer = prefabOptions[i].destroyDelay;
}
if (prefabOptions[i].sticky == true)
{
prefabOptions[i].spawnedGameObject.transform.parent = this.transform;
}
else
{
prefabOptions[i].spawnedGameObject.transform.parent = null;
}
if (prefabOptions[i].spawnedGameObject.transform.parent == null)
{
prefabOptions[i].spawnedGameObject.transform.position = this.transform.position + prefabOptions[i].spawnPosition;
if (myControlsScript.mirror == 1)
{
prefabOptions[i].spawnedGameObject.transform.position = new Vector3(this.transform.position.x + -prefabOptions[i].spawnPosition.x, prefabOptions[i].spawnedGameObject.transform.position.y, prefabOptions[i].spawnedGameObject.transform.position.z);
}
}
else
{
prefabOptions[i].spawnedGameObject.transform.localPosition = prefabOptions[i].spawnPosition;
if (myControlsScript.mirror == 1)
{
prefabOptions[i].spawnedGameObject.transform.localPosition = new Vector3(-prefabOptions[i].spawnedGameObject.transform.localPosition.x, prefabOptions[i].spawnedGameObject.transform.localPosition.y, prefabOptions[i].spawnedGameObject.transform.localPosition.z);
}
}
if (prefabOptions[i].mirrorOnRightSide == true)
{
if (myControlsScript.mirror == 1)
{
prefabOptions[i].spawnedGameObject.transform.localEulerAngles = new Vector3(prefabOptions[i].spawnedGameObject.transform.localEulerAngles.x, prefabOptions[i].spawnedGameObject.transform.localEulerAngles.y + 180, prefabOptions[i].spawnedGameObject.transform.localEulerAngles.z);
}
}
}
if (prefabOptions[i].destroyWhenMoveEnds == true)
{
if (myControlsScript.currentMove == null
|| myControlsScript.currentMove.moveName != prefabOptions[i].move.moveName)
{
if (prefabOptions[i].spawnedGameObject != null)
{
if (prefabOptions[i].disableGameObject == true)
{
prefabOptions[i].spawnedGameObject.SetActive(false);
}
else
{
Destroy(prefabOptions[i].spawnedGameObject);
}
}
}
}
if (prefabOptions[i].destroyWhenTimerEnds == true)
{
if (prefabOptions[i].destroyTimer > 0)
{
prefabOptions[i].destroyTimer -= (float)UFE.fixedDeltaTime;
}
else
{
if (prefabOptions[i].spawnedGameObject != null)
{
if (prefabOptions[i].disableGameObject == true)
{
prefabOptions[i].spawnedGameObject.SetActive(false);
}
else
{
Destroy(prefabOptions[i].spawnedGameObject);
}
}
}
}
}
}
}
}
I got an error on line 132
prefabOptions[i].spawnedGameObject.SetActive(false);
I updated the script, thanks for the report.
Thank you for the updates. It seems like the "time duration" is gone. Did you put the updates in a previous reply post?
I deleted the old script post.
Copy the post with the new code in it. You might have the old post's code still.
Your looking for destroy delay.
@FreedTerror: It works! Thank you!
Universal Fighting Engine Forum → Source Coding → Destroy character move's particle effect after they get hit
Powered by PunBB, supported by Informer Technologies, Inc.