x


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 forcollider' and no extension method collider' of typeUnityEngine.Vector3' could be found (are you missing a using directive or an assembly reference?)

more ▼

asked Mar 30 '12 at 10:12 AM

Tomomoto gravatar image

Tomomoto
-4 5 6 7

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Mar 30 '12 at 02:49 PM

TheLedworks gravatar image

TheLedworks
37 2 5 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4374
x1765
x155

asked: Mar 30 '12 at 10:12 AM

Seen: 515 times

Last Updated: Mar 30 '12 at 02:49 PM