using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(WallController))]
public class TracerController : MonoBehaviour {

    // wenn Sie diese Checkbox aktivieren, pausiert der
    // Editor nach jeder Drehung, was zum Debuggen praktisch ist
    public bool pauseOnTurns = false;

    public float baseVelocity = 5F;
    private Rigidbody myRigidbody = null;

    private WallController wallController = null;

    void Awake() {
        myRigidbody = GetComponent<Rigidbody>();
        wallController = GetComponent<WallController>();
    }

    void Start() {
        myRigidbody.velocity = transform.forward * baseVelocity;
        wallController.TracerTurned();
    }

    void Update() {
        float rotation = 0F;

        if (Input.GetKeyDown(KeyCode.LeftArrow)) {
            rotation = -90F;
        } else if (Input.GetKeyDown(KeyCode.RightArrow)) {
            rotation = 90F;
        }

        if (rotation != 0F) {
            transform.Rotate(0F, rotation, 0F);
            myRigidbody.velocity = transform.forward * baseVelocity;

            wallController.TracerTurned();
            if (pauseOnTurns) {
                Debug.Break(); // Den Editor bei jeder Drehung anhalten
            }
        }
    }
}
