The title might be confusing so sorry about that but basically I have a raycast script to hit the objects the player can pickup but currently it just destroys the game object. I want the player to be able to press E send the raycast and when it hits game object set the gameobject to the bottom right hand side of screen like their holding it. I have tried using transform and whenever I look up and down the object would move with it when I want it to stay always in bottom right until they place it.
Any help would be much appreciated!
My pickup code currently which just destroys game object:
public class PickUp : MonoBehaviour
{
public int distance;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
Grab();
}
}
void Grab()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
Debug.DrawRay(ray.origin, ray.direction * distance, Color.red, 100, false);
if (Physics.Raycast(ray, out hit, distance))
{
if (hit.transform.CompareTag("Item"))
{
Debug.Log("Item Hit");
GameObject ItemGrabbed = hit.transform.gameObject;
Destroy(hit.transform.gameObject);
}
}
}
}