Esempio n. 1
0
    // Update is called once per frame
    // Move units around as per the instructions from the database.
    void FixedUpdate()
    {
        SyncUnits();
        foreach (KeyValuePair <GameObject, Vector3> car in targets)
        {
            if (!car.Key.GetComponent <CarElements>().hit)
            {
                try {
                    car.Key.transform.LookAt(car.Value);
                } catch (Exception e) { Debug.Log(e.ToString()); }
            }
        }
        foreach (KeyValuePair <string, GameObject> car in Connect.hashes)
        {
            if (car.Value.rigidbody.constraints == RigidbodyConstraints.None)
            {
                continue;
            }
            car.Value.transform.Rotate(new Vector3(-car.Value.transform.eulerAngles.x, 0, 0));
            car.Value.rigidbody.constraints = car.Value.rigidbody.constraints | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            car.Value.transform.position    = new Vector3(car.Value.transform.position.x, 0.1f, car.Value.transform.position.z);
        }
        List <GameObject> toRemove = new List <GameObject>();

        foreach (KeyValuePair <GameObject, Vector3> target in targets)
        {
            if (!Connect.hashes.ContainsValue(target.Key))
            {
                toRemove.Add(target.Key);
                continue;
            }
            // Handle responses.
            Connect.ResponseSpooler(target.Key.name, "locator",
                                    Mathf.Round((target.Key.transform.position.x + 50) * 10).ToString() + "," +
                                    Mathf.Round((target.Key.transform.position.z + 50) * 10).ToString());
            // Debug.Log("Distance: " + Vector3.Distance(target.Key.transform.position, target.Value).ToString());
            if (Central.VerticalDistance(target.Key.transform.position, target.Value, 2.5f))
            {
                target.Key.rigidbody.velocity = Vector3.zero;
                toRemove.Add(target.Key);
                continue;
            }
        }
        foreach (GameObject idleCar in toRemove)
        {
            targets.Remove(idleCar);
        }
        HandleActions();
    }