Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (alltrains.Count != null)
        {
            GameObject       Scripts       = GameObject.Find("Scripts");
            pointclickcreate citylocations = Scripts.GetComponent <pointclickcreate> ();
            //alltrains [0].transform.rotation = Quaternion.LookRotation (new Vector3(citylocations.line1[0].location.x,citylocations.line1[0].location.y, citylocations.line1[0].location.z));
            //rigid.AddForce (transform.forward*5);
            if (citylocations.line1.Count > 0 && alltrains.Count > 0 && linecreated == false)
            {
                test.transform.position = citylocations.line1 [1].location;
                print("This is going");
                if (Mathf.Approximately(citylocations.line1 [0].location.x, alltrains [0].transform.position.x))
                {
                    alltrains [0].transform.LookAt(test.transform);
                }
                alltrains [0].transform.Translate(transform.forward * Time.deltaTime * 0.5f, relativeTo: Space.Self);
                linecreated = true;
            }
            //print (citylocations.line1 [1].location);

            /*if (Mathf.Approximately(citylocations.line1 [1].location.x, alltrains [0].transform.position.x)) {
             *      test.transform.position = citylocations.line1 [0].location;
             *      alltrains [0].transform.LookAt (test.transform);
             *      print ("Location reached");
             * }
             */
        }
    }
Exemple #2
0
    /*
     * void Update(){
     *      GameObject Scripts = GameObject.Find ("Scripts");
     *      pointclickcreate citylocations = Scripts.GetComponent<pointclickcreate> ();
     *      print ("Collided");
     *
     *      if (other.name == traintarget.name) {
     *              //moves train forward along the line
     *              if (citycoords != citylocations.line1.Count && moveforward == true) {
     *                      traintarget.transform.position = citylocations.line1 [citynumber].location;
     *                      transform.LookAt (traintarget.transform);
     *                      citynumber++;
     *              }
     *              if (citycoords == 0) {
     *                      moveforward = true;
     *                      citycoords++;
     *              }
     *              //Detects if it is on the last city, then reverses the order
     *              else if (citycoords == citylocations.line1.Count) {
     *                      moveforward = false;
     *                      citynumber--;
     *                      traintarget.transform.position = citylocations.line1 [citynumber].location;
     *                      transform.LookAt (traintarget.transform);
     *
     *              }
     *      }
     * }
     */
    void Start()
    {
        traintarget = GameObject.Find("traintarget");
        GameObject       Scripts       = GameObject.Find("Scripts");
        pointclickcreate citylocations = Scripts.GetComponent <pointclickcreate> ();

        traintarget.transform.position = citylocations.line1 [1].location;
        transform.LookAt(traintarget.transform);
    }
Exemple #3
0
    void OnTriggerEnter(Collider other)
    {
        GameObject       Scripts       = GameObject.Find("Scripts");
        pointclickcreate citylocations = Scripts.GetComponent <pointclickcreate> ();

        print("Bad collision");
        if (other.gameObject.transform.tag == "target")
        {
            print("Collided");
            lookatcheck = true;
            //moves train forward along the line
            if (citynumber != citylocations.line1.Count && backwards == false)
            {
                citynumber++;
                print("Citycoords: " + citycoords + " City Number: " + citynumber + " Lin Count: " + citylocations.line1.Count);
                traintarget.transform.position = citylocations.line1 [citynumber].location;
                transform.LookAt(traintarget.transform);
                citycoords++;
                if (citynumber == citylocations.line1.Count - 1)
                {
                    backwards = true;
                    print("Backwards was triggered");
                }
            }
            //when the train hits the first city in the line again, it turns back around
            else if (citynumber == 0)
            {
                //moveforward = true;
                citynumber++;
                backwards   = false;
                lookatcheck = true;
                print("Backwards fix triggers");
            }
            //Detects if it is on the last city, then reverses the order
            else if (backwards == true)
            {
                //moveforward = false;
                citynumber--;

                /*
                 * if (citynumber == 0) {
                 *      traintarget.transform.position = citylocations.line1 [citynumber+1].location;
                 * }
                 */
                traintarget.transform.position = citylocations.line1 [citynumber].location;
                transform.LookAt(traintarget.transform);
                print("Citycoords: " + citycoords + " City Number: " + citynumber + " Lin Count: " + citylocations.line1.Count);
                print("Backwards happened");
            }
        }
    }