﻿// Classe portée par un cube
// Pre: threshold est la distance maximale entre Tcube du cube et la pince, c'est-à-dire Otool
// Post: EstSelectionnable = true et le cube est rouge ssi le cube est sélectionnable par Otool suivant la norme euclidienne, sinon le cube est gris
//       
using UnityEngine;
using System.Collections;

public class SelectionnableDistScriptTP2scene3 : MonoBehaviour {
    public bool EstSelectionnable=false;
    public float threshold = 0.1F;
    public ToColor gestionCouleurs;
    private GameObject Tcube; // Sommet du cube
    private Vector3 Tcube_init_position;
    private GameObject Otool;
	// Use this for initialization
	void Start () {
        Tcube = transform.Find("Tcube").gameObject;
        Tcube_init_position = Tcube.transform.position;
        Otool = GameObject.Find("Otool");
	}
	
	// Update is called once per frame
	void Update () {
        Vector3 Otool_position = Otool.transform.position;
        Vector3 Tcube_position = Tcube.transform.position;
        float norm;
        norm = (Otool_position - Tcube_position).sqrMagnitude;
        EstSelectionnable = (norm < threshold*threshold);
        if (EstSelectionnable)
            gestionCouleurs.SetColor(Color.red);
        else
            gestionCouleurs.SetColor(Color.grey);
      
    }

}
