How do I get my Fireball toward my mouseposition?(some non working tries example in here :3)

Iam complety new to unity, and programming etc. so i would appreciate if anyone can help me :3

I been trying to get a prefab position, when my “charchter” (a cube at the momemnt) istantiate it. or somehow my stupid fireball(prefab) when created to go to my mouseposition somehow. oh iam trying to do a 3d game for my school project

the first alternative use these variables.

	public GameObject Target;
public int MovementSpeed = 5;
Vector3 TargetVector3;

	Target = GameObject.FindGameObjectWithTag("SpellsTarget");
	TargetVector3 = Target.transform.position;
	
	Debug.Log(Target);

alternative try 2


Target = GetComponent;
TargetVector3 = Target.transform.position;


3rd try


Direction = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
	if(Physics.Raycast(Direction,out hit,100))
	{
		TargetPosition = new Vector3(hit.point.x,0,hit.point.z);
		Debug.DrawLine(Direction.origin,hit.point);
	}

(
from another script
i try to acess the TargetPosition by doing

Controller_Movements RayHitPoint = GetComponent<Controller_Movements>();
TargetPosition = new Vector3(RayHitPoint.TargetPosition.x,
0,
RayHitPoint.TargetPosition.z);


another try is


TargetPosition = GameObject.FindGameObjectWithTag(“SpellsTarget”).transform.position;
transform.position = new Vector3(TargetPosition.x,0,TargetPosition.z);

(and more)
(cant bother to write down more just need ONE of these to work :frowning:
)
i just want to somehow to get my “fireball” toward my mouseposition.
be it either raycast or toward a object spawning near my mouse.
(i have a working code where i can spawn a empty object on my mouse position)

Have an empty behind the camera which spawns fireballs. Then, use Physics.Raycast to find the point in your game that the mouse is over, and then use Vector3.Interpolate between the fireball spawner and the point on the ground! The cleanest way of doing that, would be to spawn the fireball, and then pass an init method which does something like this-

public void Init(Vector3 newTarget)
{
    target = newTarget;
    startPos = transform.position;
}

then in your Update-

void Update()
{
    shotLocation += Time.deltaTime * shotSpeed;
    transform.position = Vector3.Lerp(startPos, target, shotLocation);
    if(shotLocation >= 1)
    {
        Explode();
    }
}

When you spawn the fireball, do something like this-

GameObject newFireBall = Instantiate(fireballPrefab, transform.position, Quaternion.identity) as GameObject;
newFireBall.SendMessage("Init", targetPoint);