Home>

Excuse me. I'm making action games with unity. I want to add an effect when an enemy character appears
http://jeanmoreno.com/unity/cartoonfxfree/
No. 14
It's not a child object of the character, but it moves together
https://gametukurikata.com/effect/appeareffect
I am doing this while watching this site.
If so, please tell me what to do.

using UnityEngine;
using System.Collections;
public class AppearEffect: MonoBehaviour
{
    // effect to appear
    [SerializeField]
    private GameObject effectObject;
    // number of seconds to turn off effect
    [SerializeField]
    private float deleteTime;
    // Offset value of the appearance position of the effect
    [SerializeField]
    private float offset;
    // Use this for initialization
    void Start ()
    {
        // Instantiate effect when game object appears
        var instantiateEffect = GameObject.Instantiate (effectObject, transform.position + new Vector3 (0f, offset, 0f), Quaternion.identity) as GameObject;
        Destroy (instantiateEffect, deleteTime);
    }
}


  • Answer # 1

    Instantiate (effectObject, transform.position + new Vector3 (0f, offset, 0f), Quaternion.identity)
    Although Quaternion.identity is specified as the third argument, the value of the transform's Rotate becomes (0,0,0) in this case.
    If you click on that prefab in the project window and look at the transform,
    I think the rotation value is not (0,0,0).
    This is because the author of this effect did not make it play correctly when the rotation is (0,0,0).
    Instantiate (effectObject, transform.position + new Vector3 (0f, offset, 0f), effectObject.transform.rotation)
    Now you can play it correctly.