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
)
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)