How to move two objects with one script?

Hi , I have been following this old tutorial on how to create a boardgame
http://classes.design.ucla.edu/Winter11/157B/?page_id=34

They did it in javascript, but I translated in c#.
http://classes.design.ucla.edu/Winter11/157B/?page_id=34

I ran into an issue when I tried to add a second player to the game. Both players are using the same script but only one object is moving after each dice roll. I would of expect both to move at the same time, but the only thing they both do is to move to the starting spot.
Why is it that only one object is moving even though they are using the same script? What would be the best way to get the other player to move?
Thanks

using UnityEngine;
using System.Collections;

public class MovePlayer : MonoBehaviour {
    public string dieName = "GroundPlane";
    public double allowedDistance = 0.5;
    private string lastDieValue = "0";
    private GameObject tileGameObject;
    //private var target : Transform;
    Camera win;
    public double damping = 3.0;
    private SideTriggers dieValueComponent;
    private playerTurn dieValueComponent1;

    //private  target : Transform;

    private string dieValue = "";
    public int currentLocation = 1;
    public int targetLocation = 1;
    bool val = false;
    // Use this for initialization
    void Start () {
        win = GameObject.Find ("MessageCamera").GetComponent ("Camera") as Camera;
        win.enabled=false;
   

        GameObject dieGameObject = GameObject.Find(dieName);
        GameObject dieGameObject1 = GameObject.FindWithTag ("SixSidedDie");

        dieValueComponent = dieGameObject.GetComponent("SideTriggers") as SideTriggers;
        dieValueComponent1 = dieGameObject1.GetComponent("playerTurn") as playerTurn;



        tileGameObject = GameObject.Find("tile" + currentLocation.ToString() + "target" );
        transform.position = tileGameObject.transform.position;
        transform.rotation = tileGameObject.transform.rotation;
        //target = tileGameObject.transform;


    }
   
    // Update is called once per frame
    void Update () {
        // get the new transform if necessary
        dieValue = dieValueComponent.facedValue;
   

        if (dieValueComponent1.playStarted) {
            //lastDieValue != dieValueComponent.facedValue &&

            if ( lastDieValue != dieValueComponent.facedValue && dieValueComponent.facedValue != "0" && dieValueComponent1.turnBegun ) {



                currentLocation += 1;




                targetLocation    += int.Parse (dieValueComponent.facedValue);

                if (currentLocation > 16)
                    currentLocation = 16;
                if (targetLocation > 16)
                    targetLocation = 16;
                tileGameObject = GameObject.Find ("tile" + currentLocation + "target");
                //GameObject tileGameObject = GameObject.Find("tile2target");
                //tileGameObject.GetComponent<Renderer> ().transform.position;

                // target = tileGameObject.GetComponent<Renderer> ().transform;
            dieValueComponent1.turnBegun = false;

            }

            if (lastDieValue != "0") {
                float dist = Vector3.Distance (transform.position, tileGameObject.GetComponent<Renderer> ().transform.position);
                if (dist > allowedDistance) {
                    float time = Time.deltaTime * (float)damping;
                    transform.position = Vector3.Lerp (transform.position, tileGameObject.GetComponent<Renderer> ().transform.position, time);
                    transform.rotation = Quaternion.Slerp (transform.rotation, tileGameObject.GetComponent<Renderer> ().transform.rotation, time);

                } else if (currentLocation != targetLocation) {
                    // reset the target
                    currentLocation += 1;
                    if (currentLocation > 16)
                        currentLocation = 16;
                    tileGameObject = GameObject.Find ("tile" + currentLocation.ToString () + "target");
               

                    //target = tileGameObject.transform;
                }
                ///int.TryParse
            }
            lastDieValue = dieValueComponent.facedValue;

        }
    }
}

You could have 2 instances of 1 script that move (2) objects, or you could have 1 script that moves two objects (one instance). It’s no problem, either way.
Honestly, I didn’t read the full script there.

I can give you two quick examples:
1 script:

public Transform FirstObject;
public Transform SecondObject;
// when you're moving
FirstObject.position += new Vector3(5,2,0);
SecondObject.position = FirstObject.position;

Sort of the same idea, if you have 2 scripts, but you have just 1 transform (per script).

Anyways, back to that tutorial… C# is by far preferred here for help/usage, so it’s good that you’re using that.
The tutorial may have shown you some parts of Unity, but it also used a lot of bad practices.
Tons of GameObject.Find (and even in Update().

I hope you’ll look at some of Unity’s in-house made tutorials and try to learn and have some fun with those.

Hope the small examples gave you some insight. Have fun :slight_smile:

Thank you for the help! well definitely check out the in house tutorials.