I have an object that has both Collider2D and Rigidbody2D attached. I am able to recognize what i need to recognize in regards to the trigger piece. What i want is to move objects that is dragged onto the collider-object to be moved to Vector3(0f, 0f, 0f).
I have tested all kinds of different ways to achieve this but not succeeded. If i place a button on the scene with the same reference with the new position it works but not when i try to do it automatically.
I have tested many different ways with limited success.
void Update () {
if (stopCard == false) {
if (checkPosGameObject != null) {
print ("stopCard == false: " + checkPosGameObject.tag);
checkPosGameObject.transform.position = newVector3(0f, 0f, 0f);
print ("The pos: " + checkPosGameObject.transform.position);
stopCard = true;
}
}
}
void OnTriggerEnter2D(Collider2D col) {
print ("OnTriggerEnter2D");
checkPosGameObject = GameObject.FindWithTag (col.tag);
print (checkPosGameObject.tag);
stopCard = false;
}
//The print output:
OnTriggerEnter2D
HAB
stopCard == false: HAB
The pos: (0.0, 0.0, 0.0)
I have tried to put the position in places like OnTriggerEnter2D and others.
I guess the problem may be in how i collect the object.