I made a magnet effect but...

I made a magnet effect but it works incorrectly.

There are balls in my game scene. If the distance between the magnet object and balls were less than 2.5, then magnet effects will work.

it’s my script for the magnet effect.

function Start () {


function Update () {

var pos : Vector3 = transform.position;

    var other : GameObject = GameObject.FindWithTag("Ball");

    var dist : float;

    var ran : float;

ran = Random.Range(20,25);

    dist = Vector3.Distance(pos,other.transform.position);



But, actually it doesn’t. Only one ball is affected by magnet effect.

All balls in game scene should be affected by magnet.

What’s wrong with my script?

Plz, anybody teach it to me.

FindWithTag() returns only a single object. You want FindGameObjectsWithTag(). At the reference page, there is sample source showing you how to loop through all the object found.