Trying out Android - big problem accessing components in other game objects -

Very new to Android development. Create a game that builds and plays fine for standalone and web, but has major compiler errors for Android. From what I can tell, these errors all revolve around accessing info from other components. For instance:

	if (Vector3.Distance(myTarget.position, transform.position)<=GetComponent("MoveAI").attachDistance)
		{
		lethal = true;		
		}

I saw something regarding dynamic typing, though I’m not sure I understand and couldn’t figure out how to make this work. Unfortunately, in building for Mac standalone, this method was one I became very comfortable with and used often. Please help me understand how I can fix this code to make it work.

Thanks!

in your Unityscript files, the first thing on line 1 to add is #pragma strict

If you do that you won’t have problems going to mobile anymore.

your problem is GetComponent(…) returns an object of type Component, not an object of type MoveAI, you need to cast it first

Hey Dreamora - thanks so much. Could you, or anyone else, show me how to alter this code correctly? This is what I tried:

	var something : MoveAI = GetComponent(MoveAI);	
	if (Vector3.Distance(myTarget.position, transform.position)<=something.attachDistance)
		{
		lethal = true;		
		}

However, I still get the compiler error that says “attachDistance is not a member of UnityEngine.Component”.

Thanks

Is the other script properly named “MoveAI.js” ?
I don’t see anything wrong with the last code tbh.