RayCast triggering a gameobject

Is it possible to cast a ray. Have it hit a collider and have the collider respond to being touched via a OnTriggerEnter or the like?

I don’t believe a raycast will trigger an object’s collider, no.

However… When casting the ray, you will have a reference to the object returned. You can then with selectivity based upon it’s tag call functions within the object to trigger whatever you want.

The problem with using the reference is I’m using C# with insists on a type cast. I’m never quite sure what object I’ll trigger and the scripts are different for many of the objects. I did notice I could use a SendMessage but I’m not sure what the performance hit would be.

Edit: Wrong Post

I don’t see how that’s an issue. The objects themselves are going to be gameObject and you’ve added the script components yourself.

You may not know ahead of time what object your ray is colliding with, but you sure know from either the name or tag at runtime what it is. As you’re creating the objects , it’s a simple matter of adding some conditional logic to account for your various classes.

//pseudocode

if (rayHit.gameObject.tag == "ObjectType1") {
 // get link to ObjectType1's known script class name
 // and call the function I need
}

It could be I’m missing something, but I don’t see the problem. That is, unless you’re dynamically adding various scripts at runtime. In any event if your object doesn’t have a known class ahead of time, then SendMessage would certainly work.

if you read the initial post, he wasn’t asking how to cast a ray. I don’t see what the point of your post is. A lot of your posts seem either to be downright incorrect, misleading or simply useless clutter.