How to find (and remove) references to GameObject C#
I want refer to GameObject but it is already been referred to. And therefore it gets referred to several times. I want to find all references to this gameObject and remove them before re-referring again.
How to remove references when you don't know how many of references are there ?
...........
Simple Example Situation: supose you have two instances of players: the_enemy, and the_doctor. Also i have gameObject the_target_1. At some point during play I refer to the_target_1 in script of the_enemy :
SelectedPlayer.GetComponent<the_enemy_script>().WhatToShootAt=the_target_1.gameObject;
Than, later at some point, i want to refer to the_target_1 in script of the_doctor:
SelectedPlayer.GetComponent<the_doctor_script>().WhatToRepair=the_target_1.gameObject;
The problem is that game object the_target_1 still is refered in enemy script.
I actually expected that once refered object automatically nulls all references, but but it does not. What I am looking is something like this:
the_target_1.gameObject.nullThoseReferencesBySomeMagic();
SelectedPlayer.GetComponent<the_doctor_script>().WhatToRepair=the_target_1.gameObject;
Thanks for help.
Of course once i find all references I can just go to enemy script and null it from there... but that is not my question. My question is how to remove references without knowing them?