Hi, I’m having little trouble with this. I want to create a magnet effect to draw my Coins gameObject towards the player.
using UnityEngine;
using System.Collections;
public class MagnetScript : MonoBehaviour {
public GameObject attractedTo;
public float strengthOfAttraction = 5.0f;
void Update()
{
Vector3 direction = attractedTo.transform.position - transform.position;
rigidbody2D.AddForce(strengthOfAttraction * direction);
}
}
This is my code, but the problem is that all the other gameObjects are moving in the direction. Please help me with this