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…

  1. Should / Can I send an array with the two details ?

  2. 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);
		}

1 Answer

1

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.