using UnityEngine;
using System.Collections;

public class WallController : MonoBehaviour {

    public Transform tracerReferencePoint;
    public Collider tracerCollider;
    public WallSegment wallPrefab;

    // Referenz auf unser Objekt "Walls" unter "Player"
    public Transform wallsParent;

    private WallSegment currentWall = null;

    // ein einfacher Zähler für unsere Wände
    private int wallCounter = 0;

    public void TracerTurned() {

        if (currentWall != null) {
            currentWall.StopGrowing();
            Physics.IgnoreCollision(tracerCollider,
                        currentWall.wallCollider,
                        false);
        }

        currentWall = (WallSegment)Instantiate(
                              wallPrefab,
                              tracerReferencePoint.position,
                              tracerReferencePoint.rotation);

        Physics.IgnoreCollision(tracerCollider,
                                currentWall.wallCollider);

        currentWall.TracerReferencePoint = tracerReferencePoint;

        // das neue Objekt unter "Walls" hängen:
        currentWall.transform.parent = wallsParent;

        // das neue Objekte benennen: WallSegment.000, WallSegment.001 usw.
        currentWall.name = string.Format("WallSegment.{0:000}", wallCounter++);
    }

}
