Multiple Objects Interfereing with each other?

Hi guys, well i had an idea for weapon pickups in my game that involved only on prefab for all of them called “WeaponPickup”.

This object has a script called “scrPickup” and from the inspector every variable is set, eg. what model to be displayed and what ammo to be recieved if it is picked up. Within this script the Vector3.Distance is measured from the player to the pickup and tested if it is less than 3.

Now this works 100% if there is only one of these “WeaponPickup” but with more than one it will not show the text that needs to be displayed.

Well so far this is my code in “scrPickup” and i was wondering how to make it compatible with more than one of the same instance with different values.

This script is run in the update function

    function PickupCheck()
var playerScript =  player.GetComponentInChildren(scrPlayer);

    playerDistance = Vector3.Distance(transform.position,player.localPosition);
    pickupText = "Press 'F' to pick up " + pickupName;
 if (playerDistance <= 3)
 playerScript.pickupText = pickupText;
 if (Input.GetKeyDown('f'))
 playerScript.weapon[playerScript.currWeaponSlot] = pickupName;
 print('You picked up the' + pickupName);
 playerScript.pickupText = '';
 playerScript.pickupText = '';

Now this script works on one of the ‘WeaponPickups’ in the scene but no others

Thanks for any help
~ Myhijim

If you have more than one object then the fact you always reset pickupText means that all of the items are setting it to empty, not just the one that you were close to.

I suggest you add a GameObject reference to playerScript and set it to the pickup when it is the one which is close, then only ever reset the pickupText if the game objects match.

I ended up fixing it by moving the entire code to the OnGUI function, this had to do with how i was calling it in the On GUI function, I was calling in On GUI

if (playerDist <=3)

Thus this code was basically crossing itself out because one would test positive to the distance and the other would’nt.

Thanks for all the assistance anyway!