Type 'Force' does not contain a definition for 'Operation'

Ok. So I have a problem with communication between two scripts.

First I’m sending you the part of my first script below:


In this script I have a variable of type GameObject called “Glass”. I’m using it to call my functions from other script which are attached to Glass’s childrens. These scripts are called “Force” and they have a “Operation” method which have a argument of type Transform.

Below my function in script “Force”:

public void Operation(Transform Direction)
		Debug.Log ("Function called");

		float Force = Random.Range(5f, 10f);
		rigidbody.AddForce(Direction.forward * Force, ForceMode.Impulse);

All is going well but when I’m playing the game I have a warning:

Type ‘Force’ does not contain a definition for ‘Operation’ and no extension method ‘Operation’ of type ‘Force’ could be found (…).

GetComponentsInChildren returns an array of components, while GetComponentInChildren (notice the “s” is gone) jsut returns the first found component. You’re trying to execute a function on a list now! :wink:

if you want each child with a Force component to execute the function:

For(int i = 0; i < Glass.GetComponentsInChildren().Length; i++)

just one:
didn’t check for compile errors, hope this puppy runs!