- Home /
If ray in contact with collider...
Why it dsnt work? (C#) What I need to do with it - if ray from "A" script in contact with collider of object attached to "B" script, then in "A" something doing:
Vector3 ray = transform.TransformDirection(Vector3.forward);
Debug.DrawLine(transform.position, ray, Color.green);
pickup = ray.collider.GetComponent<rev_pickup>();
if(pickup != null) { do(); }
Error:
error CS1061: Type UnityEngine.Vector3' does not contain a definition for
collider' and no extension method collider' of type
UnityEngine.Vector3' could be found (are you missing a using directive or an assembly reference?)
Answer by TheLedworks · Mar 30, 2012 at 02:49 PM
kinda confusing the way you worded it but i guess your trying to check if a script is attached via raycast right?
Vector3 fwd = transform.TransformDirection(Vector3.forward);
RaycastHit hit;
if(Physics.Raycast(transform.position, fwd, hit, 10)) {
if(hit.GetComponent<rev_pickup>())
{
//do your thing here :D
}
}
*btw just wrote this on here so you may have to reorganise or reword it see the reference here...
http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html?from=RaycastHit
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Raycasting ignoring small sized object 1 Answer
Multiple Cars not working 1 Answer
Can't get a laser working properly. 2 Answers