this script i attach to a collider and it pulls objects accross the colliders axis i chose. so if i set it to x axis any object that enters world travel along the colliders x axis at a speed i chose. but i want any object that enters just to move across the collider without following an axis. how can i do this?
here is the script i attach to the colliders.
@Priyanka-Rajwanshi
@Bunny83
@Kilsnus
@davidcox70
@oroora6_unity
private List pullObjects;
public Vector3 pullDirection;
public float pullSpeed;
void Start () {
pullObjects = new List ();
}
void Update () {
foreach (GameObject obj in pullObjects) {
obj.transform.Translate (Time.deltaTime * pullSpeed * pullDirection,transform);
}
}
public void OnTriggerEnter(Collider coll)
{
if (coll.gameObject.gameObject.tag == "Untagged") {
pullObjects.Add (coll.gameObject);
}
}
public void OnTriggerExit(Collider col)
{
if (col.gameObject.gameObject.tag == "Untagged") {
pullObjects.Remove (col.gameObject);
}
}
↧