lvl controller shall find the object an destroy it

well well…i have got a problem getting my level controller to destroy an object by it´s name.
first of all i set my obect´s name to it´s id

this.name = gameObject.GetInstanceID().ToString();
missileID = int.Parse(this.name);
//Debug.Log(this.name+" / "+missileID);

after that i search for the lvl controller by it´s tag…

LvLcontroller : GameObject = GameObject.FindWithTag("LevelController");

… on a trigger event ( the missile hits it´s target) i send the id/name of the missile to the lvl controller by using:

LvLcontroller.SendMessage("DestroyFunction", missileID);

the value “arrived” at the controller an initializes this:

function DestroyFunction(missileID){
		//ObjToDestroy.name = missileID.ToString();
		Debug.Log(missileID); 
		Destroy(GameObject.Find(missileID));
}

InvalidCastException: Cannot cast from source type to destination type.
is the result.

so whats wrong with this idea?

gameObject.name is the object’s name, what you’re doing is getting a unique numerical identifier
.Find() needs a string parameter and you’re giving it an integer.

Why don’t you just send the actual object to destroy to the DestroyFunction?

well…i´m coding for hours and i don´t see your solution :smile:
pls tell me how i can send the “actual” object to the destroy function? :smile:

the idea was to destroy just this one object that hits the collider, beause the missile “transports” the dmg value… and with an static dmg var sometimes the trigger->destroy was faster than substracting the dmg from the missile :wink: bad bad static var! …thats why im thought “safty first” destroy the object by it´s unique id…
edit:
right now i´m using the OnTriggerEnter by the missile itself to destroy it after sending the dmg value to launcher target and from there to the script which handles the energy/shield calculation :smile: …“var flipper”…but it works