Question by
eliaslinde · Jul 25, 2018 at 12:43 PM ·
raycastraycastingtag
Raycast objects with a tag C#
I am trying to make a script that can pick up an object with the tag Holdable (it is also the gameObject). E.g I want the raycasting only working on the things that are tagged Holdable. I have tried to figure out how, but have not been successful. Thanks in advance! I have no compiler errors. Here's an image of my inspector: https://imgur.com/a/g9mWwdn and here's my script:
{public Transform Empty;
public Camera camera;
void Update()
{
RaycastHit hit;
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
if (Input.GetMouseButton (0) && Physics.Raycast(ray, out hit))
{
gameObject.transform.position = Empty.transform.position;
}
}
Comment