I hit a gameObject with my raycast by the help of assinging a tag. Now i want to get the gameObject i hit and move it to a position via the same script. How would i be able to do that?
hit.gameObject.transform.position doesnt work but i want it to look something like that.
This might not work, but I suggest you want it to look something like this!
To get better answers, expand the question or ultimately provide examples of your code/scene.
Be sure to raycast properly.
var hitGO : GameObject;
hitGO = hit.gameObject;
Update(){
var camera = GetComponent.<Camera>();
var mousePos = camera.ScreenToWorldPoint(Input.mousePosition);
}
if ( Input.GetMouseButtonDown(0) ){
hitGO.transform.position = Vector3(mousePos.x,transform.position.y,mousePos.z);
}
In other object which you want to move ,Add move functionality, if you want constantly move object then use Vector3.lerp or Vector3.MoveTowards + coroutines else use rigidbody.AddForce
Once object hit by ray cast do this,
if(hit.gameobject.tag == "DesireObject")
{
//run this function
hit.gameObject.getComponent<MovementScript>().movementFUnction();
}
Hope that help you, let me know if you still face same problem.