Move a particle with code

I have a particle effect that looks like sparks. It plays whenever a player hits a certain object with a raycast. The problem is that the particle effect is placed wherever the player hits the object, often in the middle of the mesh so it looks strange. Would there be a way to make the sparks always play on a certain part of the object (like on the top of it?) Or (even better) make the particle effect’s shape the same shape as the object so it looks like the entire object is making sparks?

Thanks!
Here is my incredibly confusing script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DecayRay : MonoBehaviour
{
    private int count = 1;
    public GameObject sparks; //The particle effect
    private GameObject obj;
    private int cd = 1;
    RaycastHit hit;


    IEnumerator transform2()
    {
        sparks.transform.position = hit.point; //this changes the particle effect position to wherever the player hits the object.
        sparks.SetActive(true);
        yield return new WaitForSeconds(2);
        sparks.SetActive(false);
        obj.GetComponent<DecayInto>().startObject.SetActive(true);
        obj.GetComponent<DecayInto>().decayObject.SetActive(false);
        cd = 1;
    }
    IEnumerator transform1()
    {
        sparks.transform.position = hit.point;
        sparks.SetActive(true);
        yield return new WaitForSeconds(2);
        sparks.SetActive(false);
        obj.GetComponent<DecayInto>().startObject.SetActive(false);
        obj.GetComponent<DecayInto>().decayObject.SetActive(true);
        cd = 1;
    }


    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (((Physics.Raycast(transform.position, transform.forward, out hit) && hit.transform.tag == "cube") && count == 1) && cd == 1)
            {
                cd = 0;
                obj = hit.transform.gameObject;
                StartCoroutine(transform1()); 
                count = 2;
            }
            else if (((Physics.Raycast(transform.position, transform.forward, out hit) && hit.transform.tag == "cube") && count == 2) && cd == 1)
            {
                cd = 0;
                StartCoroutine(transform2());
                count = 1;
            }
            else
            {
                //nothin.
            }
       }
   }
}

You’re welcome

An idea of how to do this could be attaching the particle effects as a child of the object (this way you can edit it to fit the object and place it where you want) and in the raycast you could check the child object for a particlesystem component and activate the particle this way

Example :

        if (Physics.Raycast(transform.position, transform.forward, out hit, 10.0f))
        {
            if (hit.transform.GetChild(0).GetComponent<ParticleSystem>() && hit.transform.tag == "TAG")
            {
            
            }
        }

How is that even remotely helpful?

You’d probably want to grab the appropriate sub-emitter, which is basically a particle system in a particle system
https://docs.unity3d.com/ScriptReference/ParticleSystem.html
From there you can change the shape
https://docs.unity3d.com/ScriptReference/ParticleSystem-shape.html

This doesn’t really solve my issue, but thanks.

Would you possibly know how to do the other thing I requested (which is just making the particle system emit in opposite to whatever face it hits, so it always looks like it’s coming out of the object?)

If you know the face then just position the GameObject with the particle system appropriately and make the system emit in world space.