Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Move objects in a specific location

Discussion in 'Scripting' started by gnaneswara088, Feb 6, 2020.

  1. gnaneswara088

    gnaneswara088

    Joined:
    Feb 1, 2020
    Posts:
    3
    {
    public GameObject item;
    public GameObject tempParent;
    public Transform guide;


    void Start()
    {
    item.GetComponent<Rigidbody>().useGravity = true;

    }

    void Update()
    {

    }
    private void OnMouseDown()
    {
    item.GetComponent<Rigidbody>().useGravity = false;
    item.GetComponent<Rigidbody>().isKinematic = true;
    item.transform.position = guide.transform.position;
    item.transform.rotation = guide.transform.rotation;
    item.transform.parent = tempParent.transform;
    }
    private void OnMouseUp()
    {
    float horizontalInput = 24.63001f;
    float verticalInput = 1.017074f;
    item.GetComponent<Rigidbody>().useGravity = true;
    item.GetComponent<Rigidbody>().isKinematic = false;
    transform.position = new Vector3(horizontalInput, verticalInput, 23.95186f);


    I tried to carry a object with forklift when i hit a mouse it will stay on the forklift but when i released mouse it won't go to the specific location which i give, i don't know how or what to do I am stuck on this please help me with this and thank you in advance
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Please use code tags, and please post the complete code.

    But from what I see, you need to unparent the item from the temporary parent by

    Code (CSharp):
    1. transform.parent = null;
    -ch
     
    gnaneswara088 likes this.
  3. gnaneswara088

    gnaneswara088

    Joined:
    Feb 1, 2020
    Posts:
    3
    this is all my code