U
U
Uncle Bogdan2021-07-30 15:53:53
Unity
Uncle Bogdan, 2021-07-30 15:53:53

Why does Transform fly far away, but does not change position?

Such a joke, the only thing I do in the code is change the parent, but for some reason _placeTransform is far from its original position. _placeTransform is empty.

using UnityEngine;

public class PcCase : MonoBehaviour
{
    [SerializeField] Transform _placeTransform;

    private void OnCollisionEnter(Collision collision)
    {
        if(collision.collider.GetComponent<Motherboard>())
        {
            SetMotherboard(collision.collider);
        }
    }

    private void SetMotherboard(Collider motherboard)
    {
        motherboard.attachedRigidbody.isKinematic = true;
        motherboard.attachedRigidbody.useGravity = false;

        motherboard.transform.parent = _placeTransform;
        motherboard.transform.localPosition = Vector3.zero;
        motherboard.transform.rotation = transform.rotation;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question