How to get the position of an object from another script and force the object to move to the resulti

There are two scripts, “Docs” and “Letter”.

When you pick up a note, everything is ok, but when it needs to be returned to its place, it falls into the same coordinate, no matter how many notes on the stage they all fall into the same position.
I made a second script where I get the position of the object on which the script is.

Now the question arose of how to force the object to move to the position that was obtained through the “Letter” script

using UnityEngine;
using System.Collections;

public class Letter : MonoBehaviour {
        public Vector3 pos;
        public GameObject[] Letter_obj;
        // Use this for initialization
        void Start () {

        }

        // Update is called once per frame
        void Update () {
                Letter_obj = GameObject.FindGameObjectsWithTag ("letter");
                pos = Letter_obj[0].transform.position;
        }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

public class Docs : MonoBehaviour
{
  public LayerMask mask;
  public FirstPersonController player;
  private bool isread = false;
  private Transform letter;
  Vector3 StartPosition;
  Quaternion StartRotation;
  private Letter Letter_obj;

  void Start () {
    player.enabled = true;
    StartPosition = Letter_obj.transform.GetComponent<Transform>().position;
    StartRotation = Letter_obj.transform.GetComponent<Transform>().rotation;

  }

  void Update () {
    if(!isread)
    {
      RaycastHit hit;
      if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 2f, mask))
      {
        if(hit.collider.tag == "letter")
        Letter_obj = hit.collider.gameObject.GetComponent<Letter>();
        {
          if(Input.GetKeyDown(KeyCode.E))
          {
            player.enabled = false;
            letter = hit.transform;
            isread = true;
          }
        }
      }
    }
    else
    {
      letter.position = Camera.main.transform.position + Camera.main.transform.forward * .5f;
      letter.LookAt(Camera.main.transform);
      if(Input.GetKeyDown(KeyCode.E))
      {
        player.enabled = true;
        isread = false;
        letter.transform.position = StartPosition;
        letter.transform.rotation = StartRotation;
      }
    }
  }
}

Please don’t add pointless polls to your post.

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run?
  • what are the values of the variables involved? Are they initialized?

Knowing this information will help you reason about the behavior you are seeing.

If you are running a mobile device you can also see the console output. Google for how.

Once that process gives you some idea of what is going on, if you still have questions,

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself: