- Home /
Raycast from secondary camera
Hello,
What I am trying to do is create a script that grabs an object by raycasting from a camera embedded within an object. I was trying to restrict it so that it would only effect objects with a specific tag. In this case it is used for a vacuum nozzle. The script I have currently is below but it is getting an error originating on line 5 saying no appropriate version of "UnityEngine.Physics.Raycast" for the argument list '\UnityEngine.Vector3)' was found. So is there a more efficient way to write this code to accomplish this or is there a resource I can look at to help me write a better version of this code?
Thanks in advance for you help.
edit**
So thanks to seeing a little more of the syntax I have changed by code to the below. Although one problem still persists and that is that I cannot get the ray to read objects with the specified tags. Is there something that needs to be done or should I be able to import fbx files into Unity and assign them their tags? So far doing this has resulted in the code printing not working. Is there some step that I for either tagging the objects or within my syntax?
var vacRange = 30.0;
function Update() {
if (Input.GetKeyDown(KeyCode.E)){
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.forward, hit, vacRange)) {
print("hit something");
if(hit.collider.gameObject.tag=="Food"){
print("hitting food");
}else{
print("not working");
}
}
}
}
Answer by DaveA · Oct 18, 2011 at 11:33 PM
Physics.Raycast needs more arguments than just position, check the manual
By manual are you referring to the support section on the unity main site?
By manual he's referring to this which leads to the scripting reference which is located on the unity homepage in the support section
Very helpful indeed, thanks, but now I can't seem to get it to work based on tagged objects.