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;
}
}
}