Help in solving mistake in my code

I have made scripts Test1 and Test2. Test1 script is looking for objects with script Test2, and when collides, variables are equating. But it works only 1 time. Thanks.

public class Test1 : MonoBehaviour
{

public string myName;
public Test2[] Cubes;
// Use this for initialization
void Start () 
{		
	Cubes = FindObjectsOfType(typeof(Test2)) as Test2[];				
}

void OnCollisionEnter()
{
	for(int i = 0;i<Cubes.Length;i++)
	{
		myName = Cubes*.name;*
  •   }*
    
  • }*

  • // Update is called once per frame*

  • void Update ()*

  • {*

  •   Debug.Log(myName);*
    
  • }*
    }
    public class Test2 : MonoBehaviour {

  • public string name = “Name”;*

  • // Use this for initialization*

  • void Start ()*

  • {*

  • }*

  • // Update is called once per frame*

  • void Update ()*

  • {*

  • }*
    }

Found information at http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html .

This is my solution :slight_smile:

void OnCollisionEnter(Collision collider)
{
 	myName = collider.gameObject.GetComponent<Test2>().name;
    				
	
}