Esempio n. 1
0
    private void UpdateSpecificDino(GameObject _node, int _index)
    {
        NodeBehavior nodeScript = _node.GetComponent <NodeBehavior>();

        if (currentNodes[_index] != null)
        {
            //if the player runs into the start node while currently on the last node
            if (nodeScript.isFinishLine == true && currentNodes[_index] == lastNode.GetComponent <NodeBehavior>())
            {
                int lapTest = 0;

                //increase the lap count
                lapCount[_index]++;

                //set the current node to the start node
                currentNodes[_index] = startNode.GetComponent <NodeBehavior>();
                nextNodes[_index]    = currentNodes[_index].NextNodes[0].GetComponent <NodeBehavior>();

                if (lapCount[_index] >= maxLap)
                {
                    var d  = dinos[_index];
                    var uc = d.GetComponent <UserControl>();
                    var ac = d.GetComponent <AIControl>();
                    uc.enabled = false;
                    ac.enabled = true;
                }

                //test to see how many player dinos have completed all of the laps
                for (int i = 0; i < dinos.Length; i++)
                {
                    if (lapCount[i] >= maxLap && dinos[i].tag == "Dino")
                    {
                        lapTest++;
                    }
                }

                //if all player dinos have completed all of the laps end the race
                if (lapTest >= connectedPlayers)
                {
                    hudScript.ShowFinish();
                    hudScript.EndRace();
                }

                if (lapCount[playerNum] > maxLap)
                {
                    hudScript.ShowFinish();
                }

                //Debug.Log("player " + _index + " current node " + currentNodes[_index]);
            }
            //if the player runs into a normal node
            else
            {
                /*Debug.Log("-------------------------");
                 * Debug.Log("you hit " + _node.name);
                 * Debug.Log("the next node is " + nextNodes[_index]);
                 * Debug.Log("the current node is " + currentNodes[_index]);
                 * Debug.Log(nodeScript == nextNodes[_index]);*/

                int j = 0;

                if (nodeScript == nextNodes[_index])
                {
                    //Debug.Log(_node.name + " is the right node");

                    foreach (GameObject n in nodeScript.previousNodes)
                    {
                        //Debug.Log("previous node " + n);
                        //Debug.Log("current node " + currentNodes[_index]);

                        if (n.GetComponent <NodeBehavior>() == currentNodes[_index])
                        {
                            //Debug.Log(nodeScript.NextNodes[j].name + " is the new next node");
                            nextNodes[_index] = nodeScript.NextNodes[j].GetComponent <NodeBehavior>();
                            //currentNodes[_index] = _node.GetComponent<NodeBehavior>();
                            currentNodes[_index] = nodeScript;
                        }

                        j++;
                    }
                }

                //calculate the distance to the finish line
                if (currentNodes[_index].NextNodes.Length != 0)
                {
                    /*Debug.Log(nextNodes[_index] + " is the new next node");
                     * Debug.Log(currentNodes[_index] + " is the new current node");*/

                    finishDist[_index] = AddUpDistance(currentNodes[_index].GetComponent <NodeBehavior>(), nextNodes[_index].GetComponent <NodeBehavior>() /*, i*/, 0);
                }
            }
        }
    }