Finding scripts on instantiated objects;

Thanks for your help!

I’m trying to figure out why I receive an error when I run this script, called “Character Destroyer”. With this script, I’m trying to find the closest object with a “Ground Placard” tag, and switch the destroyit variable in that object if the user has just typed the key that matches the answer string in that object. My debugging efforts indicate that it’s just not finding the closest object, however. Ideally, when the user pushes a key, this script should check to see if it matches the answer on the closest object. Here’s the code and the error. Any help would be a life-saver, as I’ve got to turn in this project for school! Ew.


private var target;
var characterchecker;

function Update()

function TestClosestPlacard()
target = FindClosestPlacard;
if(target != null)
characterchecker = target.GetComponent(“Character Checker”);
characterchecker.destroyit = true;

// Find the name of the closest enemy
function FindClosestPlacard () : GameObject
// Find all game objects with tag Enemy
var gos : GameObject;
gos = GameObject.FindGameObjectsWithTag(“Ground Placards”);
var closest : GameObject;
var distance = Mathf.Infinity;
var position = transform.position;
// Iterate through them and find the closest one
for (var go : GameObject in gos)
var diff = (go.transform.position - position);
var curDistance = diff.sqrMagnitude;
if (curDistance < distance)
closest = go;
distance = curDistance;
return closest;

MissingMethodException: Method not found: ‘CompilerGenerated.Character Destroyer_TestClosestPlacard$callable0$14_18.GetComponent’.
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object args)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey12.m__6 ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Type cacheKeyTypes, System.Object args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Dispatch (System.Object target, System.String cacheKeyName, System.Object args, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object args, System.Type scriptBaseType)
Character Destroyer.TestClosestPlacard () (at Assets/Scripts/Character Checking Scripts/Character Destroyer.js:17)
Character Destroyer.Update () (at Assets/Scripts/Character Checking Scripts/Character Destroyer.js:8)


I don’t work in Boo, but I think you are missing parenthesis when you try to call FindClosestPlacard.

target = FindClosestPlacard;  // sets target to be a function?

target = FindClosestPlacard();  // try this instead

Zounds! That’s it! I can’t believe it was so simple. Thanks a million. My descendants shall sing you praises for generations.