- Home /
SendMessage - how to send 2 details? - 2 Vector3's actually
Hi There,
I'm tired so for some reason trying to convert Vector3 to float etc- so can somebody tell me how I should amend this code. Bascially I want to send an object a message with the hit.point and hit.normal so that a function at the other end can do some cool stuff with it. I see that SendMessage can only send one thing at a time, I tried the code below to split it into two parts, but obviously the x and y of the Vector2 can only be floats...
Should / Can I send an array with the two details ?
Is there a better way?
Thanks!!!!
//Check for mirrors and reflect off them if you hit one.
var HitObject = hit.transform.gameObject;
if (HitObject.tag == "mirror"){
var ReflectDetails : Vector2;
ReflectDetails.x = hit.point;
ReflectDetails.y = hit.normal;
HitObject.SendMessage ("DoReflectLaser", ReflectDetails);
}
Answer by rutter · Mar 16, 2012 at 12:16 AM
Looking at GameObject.SendMessage(), it looks like the second argument can be an object of any type. You could probably create a new class which contains two vectors, and pass that.
In my opinion, though, you're probably better off getting a direct reference to the script(s) you're interested in, using GetComponent() and similar functions, and calling a function of your own.
This worked out great, don't know what I was thinking lol. And sorry about the super late response. Thanks for advice.
Your answer
Follow this Question
Related Questions
Saving Certain Vector3's positions 2 Answers
Vector3 Array Empties Its Self Immediately After Being Initialized 1 Answer
Send a message to multiple scripts within an Array - Javascript 1 Answer
Pair Switch Cases to individual elements in a Vector3 array? 1 Answer
Failed setting triangles in my mesh 1 Answer