How to Instantiate trail renderer with my dash ability?

Hi, I am a beginner. I am working on a 2D top down game by following tutorial to learn gamedev. I already have my player dash with press of a key (LeftShift). I added a few trail renderers together, turned it into a prefab and used the code below to execute it. Assigned the script to the player and the prefab to the gameobject field created by the script. But it doesn’t seem to work at all. I also tried adding this code to the dash script but that didn’t work either. Am I using the wrong code or doing something wrong in the editor? Thanks for any help.

public GameObject dashEffect;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftShift))
            Instantiate(dashEffect, transform.position, Quaternion.identity);
    }

Regards
Himanshu

I’ll move your post to the scripting forum, this isn’t a 2D related issue. Also, please post/edit code using code-tags .

You might also find the Getting Started forum useful too.

Thanks.

Best way is to attach the trail renderer to your object and set it active or inactive based on dashing status. Because a trail must follow your object to work.
If you do have to kill the trail, you can attach it to your moving object while active and then when the dash is over unparent it and then after a trail depleted kill it

Yes that worked but the thing is I need many TrailRenderers to make that effect but as a component to the player it doesn’t allow two TrailRenderers. Also I noticed trails don’t look good because it also bends if the player has taken a turn before doing a dash. I red somewhere that a line renderer would be a better choice.

You’ll have to use children objects.

I couldn’t say if a line renderer is a better choice I had never used it for trail purposes.

Yes I figured it out last night. I used a box sprite and turned its sprite renderer off then duplicated it. Earlier I was using trail renderer on the player itself. Thanks for the help. I’ll look up line renderer and see how it goes.