예제 #1
0
    public GameObject Floor;                // is the game object block that is used to create a path

    // Use this for initialization
    private void Start()
    {
        transform.eulerAngles = Vector3.zero;
        _self = this;                                                                                                                                                                       //loade this script
        Land.SetEndPoint(LandManager.CreateNext(LandManager.CreateNext(LandManager.CreateNext(LandManager.CreateNext(LandManager.CreateNext(startPoint, 0)[0], 0)[0], 0)[0], 0)[0], 0)[0]); //add 5 straight blocks when the game starts
        _prep           = false;                                                                                                                                                            //set the preperation bool to false
        PlayerTransform = GameObject.FindGameObjectWithTag("Player").transform;                                                                                                             //adding positions to the player
    }
예제 #2
0
    void OnTriggerEnter(Collider collider) //when the player enters the collider
    {
        _swipe.land = this;
        Land standing = this;                      //to start with the one the player stands on

        while (standing.Root != null)              // keep counting one block backwards
        {
            standing = standing.Root;              // till it finds the first block and set it
        }
        standing.lastActivId = lastActivCounter++; //give id to the last activated block



        if (collider.gameObject.tag == "Player" && GetComponents <BoxCollider>()[2].enabled == true) //when the player enters the rotate collider
        {
            rotate = true;                                                                           //set the bool to true
        }



        if (_isCrossway)         //if the roade is crossy
        {
            _isCrossway = false; //set the bool to false
        }


        int counter = transform.GetComponentsInChildren <Land>().Length;

        //   print("test counter: " + counter);
        if (counter >= 7)    //if there are more then 7 blocks after this block
        {
            //stop creating new blocks
            return;
        }


        if (transform.childCount >= 5)    //if there are more then 5 blocks
        {
            _isCrossway = true;           //that means it is a cross Roade
        }

        if (collider.gameObject.tag == "Player") //if the player enters the collider
        {
            if (EndPoints != null)               //if there is an end point
            {
                // print(EndPoints.Count);

                List <Land> temp = new List <Land>();  //create temperarly list to delete later
                while (EndPoints.Count > 0)            //as long as there is an end point
                {
                    if (EndPoints[0] == null)
                    {
                        EndPoints.RemoveAt(0);
                        continue;
                    }
                    print("after if there is" + temp.Count);
                    if (EndPoints[0]._nextStraight)                             //if the straight bool is true
                    {
                        temp.AddRange(LandManager.CreateNext(EndPoints[0], 0)); //add a block with a straight case
                    }
                    else                                                        //if not true
                    {
                        if (GetPossibleDirections(EndPoints[0]).Length > 0)
                        {
                            temp.AddRange(LandManager.CreateNext(EndPoints[0], GetPossibleDirections(EndPoints[0]))); //add another block
                        }
                        else
                        {
                            print("Invalid Endpoint");
                        }
                    }



                    EndPoints.RemoveAt(0);  //after we created a block after the endpoint it no longer is an endpoint, so we remove it
                }
                if (temp.Count == 0)
                {
                    throw new System.Exception("end of endpoints");
                }

                // if there is more then one endpoint mix the order
                if (temp.Count > 1)
                {
                    List <Land> temp_mix = new List <Land>();
                    while (temp.Count > 0)
                    {
                        var rnd = Random.Range(0, temp.Count);
                        temp_mix.Add(temp[rnd]);
                        temp.RemoveAt(rnd);
                    }
                    temp.AddRange(temp_mix);
                }

                EndPoints = temp;                                                                       // save the new enpoints in the list
            }
            else                                                                                        //if the list is empty
            {
                EndPoints = LandManager.CreateNext(GetComponent <Land>(), GetPossibleDirections(this)); //add a land script to add a block
            }


            if (Root != null && Root.Root != null && Root.Root.Root != null) //if the last block is there and the one before
            {
                LandManager.DeleteLand(Root.Root.Root, Root.Root);           //delet and remove the one befor the last one
            }
        }

        LandManager.CheckForMultipleRoots();  //check if there is more then one roade
    }