public void Generate() { numWagons = lettersList.Length; wagonsList = new wagon[numWagons]; Wagon = null; GameObject locomotiveGObject = Instantiate(locomotivePrefab, puntoSalida.position, Quaternion.identity); for (int i = 0; i < numWagons; i++) { GameObject wn = Instantiate(wagonPrefab, puntoSalida.position, Quaternion.identity); wn.GetComponent <wagon>().setNumberWagon(i + 1); wagonsList[i] = wn.GetComponent <wagon>(); if (i == 0) { wn.GetComponent <wagon>().Locomotive = locomotiveGObject.GetComponent <locomotive>(); } wagonLetter = lettersList[i]; wn.GetComponent <wagon>().box = Instantiate(boxPrefab).GetComponent <wagonBox>(); wn.GetComponent <wagon>().box.boxLetter = wagonLetter; } }
void Start() { generator = FindObjectOfType <trainGenerator>(); wagon = generator.Wagon; transform.position = wagon.getBoxPosition(); boxState = "Waiting"; changeBoxes = false; changePossible = false; //boxLetter = "A"; boxText = GetComponentInChildren <TextMesh>(); boxText.text = boxLetter; }
void moveBoxToWagon(wagon wn) { var heading = new Vector3(wagon.getBoxPosition().x, wagon.getBoxPosition().y) - transform.position; var distance = heading.magnitude; var direction = heading / distance; int itera = 0; if (distance >= 0.5f) { transform.Translate(direction * 2 / 3); Debug.Log(itera += 1); } else { transform.localPosition = wagon.getBoxPosition(); boxState = "Waiting"; Debug.Log("Hecho"); } }
void Start() { manager = FindObjectOfType <trainLevelManager>(); wagonAnim = GetComponent <Animator>(); wagonAnim.SetBool("Moving", true); generator = FindObjectOfType <trainGenerator>(); wBefore = generator.Wagon; generator.Wagon = this; wagonState = "Moving"; if (wBefore != null) { wBefore.wNext = this; } else { Locomotive.setNextWagon(this); } }
//SETTER public void setNextWagon(wagon wn) { nextWagon = wn; }
void Update() { switch (boxState) { case "Waiting": if (transform.localPosition != new Vector3(wagon.getBoxPosition().x, wagon.getBoxPosition().y)) { moveBoxToWagon(wagon); } else { transform.localPosition = wagon.getBoxPosition(); } /*if (transform.localPosition.y > wagon.getBoxPosition().y) * { * transform.localPosition -= new Vector3(0f, 10f) * Time.deltaTime; * } * else { transform.localPosition = wagon.getBoxPosition(); }*/ break; case "Selected": Vector2 newPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y)); transform.position = newPosition; break; case "Drop": moveBoxToWagon(wagon); break; case "Host": if (transform.localPosition.y < wagon.getBoxPosition().y + 2f) { transform.localPosition += new Vector3(0f, 10f) * Time.deltaTime; } else if (transform.localPosition.y > wagon.getBoxPosition().y + 2f) { transform.localPosition = new Vector3(transform.localPosition.x, wagon.getBoxPosition().y + 2f, transform.localPosition.z); } break; } //INTERCAMBIO DE VAGONES ENTRE CAJAS if (changeBoxes) { wagon auxW = wagon; setWagonToBox(posibleWagon.GetComponent <wagon>()); wagon.getWagonBox().setWagonToBox(auxW); auxW.setBoxToWagon(wagon.getWagonBox()); wagon.setBoxToWagon(this); auxW.getWagonBox().boxState = "Drop"; boxState = "Drop"; FindObjectOfType <AudioScript>().MakePopSound(); //genero sonido al colocar una caja. changeBoxes = false; } /* if (changeBoxes) * { * fixTimer += Time.deltaTime; * if (fixTimer >= 0.5f) { boxState = "Drop"; changeBoxes = false; } * } * else { fixTimer = 0f;}*/ }
public void setWagonToBox(wagon wn) { wagon = wn; }