For/In and SendMessage

I cannot figure out why this is not functioning, could someone please help me?

var touchReceiver = new GameObject[2];

function Update () {

for (var event : Touch in Input.touches){ //check for any touches

  //check for phase changes
  if (event.phase == TouchPhase.Began){ //if a touch begins
	for (var currentObject in touchReceiver){
		 currentObject.SendMessage ("Began");
		}
  startPosX = event.deltaPosition.x;	
  }// end if
  
  
  if (event.phase == TouchPhase.Stationary){ //if a touch is resting on the screen
  		for (var currentObject in touchReceiver){
			 currentObject.SendMessage ("Stationary");
			}
  } //end if

 if (event.phase == TouchPhase.Moved){ //if a touch is resting on the screen
  		for (var currentObject in touchReceiver){
			 currentObject.SendMessage ("Moved");
			}
  } //end if

  if (event.phase == TouchPhase.Ended){ //if a touch ends
  		for (var currentObject in touchReceiver){
			 currentObject.SendMessage ("Ended");
			}
  endPosX = event.deltaPosition.x; 
  } //end if

} //end for
} //end Update

When I run this, Unity tells me that

SendMessage Moved has no receiver!
UnityEngine.GameObject:SendMessage(String)

Also get this for each of the touch phases (Stationary, Ended, Began) of course.

I hope it’s plain, all I want to do is SendMessage to an array of objects…

Do you have a script on each GameObject in touchReceiver that provides a Began,Stationary,Moved,Ended function? If not you will get this error. You can send the message with the option SendMessageOptions.DontRequireReceiver.

I’m not a friend of SendMessage in general. I would always use direct function calls :wink:
Unfortunately you can’t define interfaces in UnityScript.

Do you have a script on each GameObject in touchReceiver that provides a Began,Stationary,Moved,Ended function? If not you will get this error. You can send the message with the option SendMessageOptions.DontRequireReceiver.
I’m not a friend of SendMessage in general. I would always use direct function calls :wink: Unfortunately you can’t define interfaces in UnityScript.

So I have to have a script with a function on each child object of the Indicator Manager?

function Moved(){
for (var event : Touch in Input.touches){ 

touchId = event.fingerId; //store the fingerId of the touch
posX = event.position.x; //store x location of touch
posY = event.position.y; //store y location of touch
touchIndicators[touchId].transform.position.x = posX/xDivisor; //move object to touch X location
touchIndicators[touchId].transform.position.y = posY/yDivisor; //move object to touch Y location


} //end for

} //end Moved

This is the function in IndicatorManager.js, attached to Indicator Manager GO, that gets called when the Moved message gets sent to the Indicator Manager GO. The touchIndicators array is a child of the Indicator Manager GO. It seems backwards to have to have a Moved() function for each child object or child array of Indicator Manager…is there a way to send the message to each object without having to have a sperate function for each one? Or, am I totally misunderstanding?

Indicator Manager Panel