Beispiel #1
0
    private void Update()
    {
        bool up    = Input.GetKey(KeyCode.UpArrow);
        bool down  = Input.GetKey(KeyCode.DownArrow);
        bool left  = Input.GetKey(KeyCode.LeftArrow);
        bool right = Input.GetKey(KeyCode.RightArrow);

        if (left && !right)
        {
            PlaneControls.Rotate(-speed);
        }
        else if (right && !left)
        {
            PlaneControls.Rotate(speed);
        }
        else
        {
            PlaneControls.Rotate(0);
        }

        if (up && !down)
        {
            PlaneControls.Move(speed);
        }
        else if (down && !up)
        {
            PlaneControls.Move(-speed);
        }
        else
        {
            PlaneControls.Move(0);
        }

        /*float disUp = 0;
         * float disLeft = 0;
         * if (up) disUp += speed;
         * if (down) disUp -= speed;
         * if (left) disLeft += speed;
         * if (right) disLeft -= speed;
         *
         * this.transform.position += Vector3.left * disLeft * Time.deltaTime * 50;
         * this.transform.position += Vector3.up * disUp * Time.deltaTime * 50;*/

        scoreText.text = "Score: " + score;
        if (!collide)
        {
            currentSpeed                 = forwardSpeedModifier;
            this.transform.position     += Vector3.forward * currentSpeed * (Time.deltaTime * 50);
            cameraPos.transform.position = this.transform.position + new Vector3(0, 0, -5);
            cameraPos.rotation           = this.transform.rotation;
        }
    }
    private void Start()
    {
        // Assign defaults for objects if they are null ( = set to nothing in editor)
        Cam   = Cam ?? GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
        Plane = Plane ?? GameObject.FindGameObjectWithTag("Player").GetComponent <PlaneControls>();

        if (Plane == null)
        {
            Plane = GameObject.FindGameObjectWithTag("Player").GetComponent <PlaneControls>();
        }

        Vector3 oldVec = Cam.transform.position;

        oldVec.x = StartPos;
        Cam.transform.position = oldVec;
    }