Hello everyone,
Im new to Unity and Im trying to prototipe a magnet efect. When the magnet comes close to any metal, I want to add some forces to repel or to atrac it to the metal. The game is a 2D platformer.
I have wrote this, but it does nothing help plz!
using UnityEngine;
using System.Collections;
public class PlayerMagnet : MonoBehaviour {
//negative repel
private bool negativeDown;
public float magnetForce = 10f;
GameObject magnet;
Vector2 forceDirection;
// Use this for initialization
void Awake () {
negativeDown = true;
magnet = GetComponent ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other){
//Magnet Above, negative down
if (magnet.transform.position.y > other.transform.position.y && negativeDown == true) {
forceDirection.Set (0f, magnetForce);
}
}
}