Post by shadex on May 9, 2017 20:38:49 GMT
I am currently working on a script to spawn a particle effect at a location. This is a state machine behavior, like MeleeAttackControl. I want to spawn the effect at an attachment point in the hand called "MagicHands". right now it's spawning at animator.rootPosition, How can i access the equip point in the hand? Below is the script
Any help would be appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngineInternal;
public class MagicAttackBehavior : StateMachineBehaviour {
// collision effect
[Tooltip("Particle Effect")]
public GameObject particle;
[Tooltip("Particle Effect")]
public float TimeToDestroyParticleEffect;
[Tooltip("Start particle effect at")]
public float startParticleEffect = 0.05f;
[Tooltip("End Particle Effect at")]
public float endParticleEffect = 0.9f;
private bool isActive;
[Tooltip("Use explosions physics")]
public bool UseMPhysics;
public float radius;
public float power;
protected GameObject clone;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (stateInfo.normalizedTime % 1 >= startParticleEffect && stateInfo.normalizedTime % 1 <= endParticleEffect && !isActive)
{
[font color="ff00e2"]clone = Instantiate(particle, animator.rootPosition, Quaternion.identity) as GameObject;[/font]
isActive = true;
UnityEngine.Object.Destroy (clone, TimeToDestroyParticleEffect);
Debug.Log ("-- Particle Effect Destroyed -- ");
if (UseMPhysics == true) {
Vector3 explosionPos = animator.rootPosition;
Collider[] colliders = Physics.OverlapSphere (explosionPos, radius);
foreach (Collider hit in colliders) {
Rigidbody rb = hit.GetComponent<Rigidbody> ();
if (rb != null)
rb.AddExplosionForce (power, explosionPos, radius, 3.0F);
Debug.Log ("-- YES Physics -- ");
}
}
else if (UseMPhysics != true) {
Debug.Log ("-- No Physics -- ");
}
}
// Activeate this after startParticleEffect
else if (stateInfo.normalizedTime % 1 > endParticleEffect && isActive)
{
Debug.Log("-- else if statement active -- ");
isActive = false;
}
}
override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//Debug.Log("On Attack Move ");
}
override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//Debug.Log("On Attack IK ");
}
}
Any help would be appreciated.