﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// Script porté par Otool
// cube est le GameObject du cube sélectionnable par la pince Otool
// Post: cube est le cube sélectionnable ssi Otool rentre en collision avec un cube TAGGE CUBE, sinon cube vaut null;
public class SelectionnableTriggerScriptTP3scene2 : MonoBehaviour
{
    private GameObject cube;
    // Start is called before the first frame update
    void Start()
    {
        cube = null;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    //-------------------------------------------
    // La pince Otool rentre en collision avec un cube
    // Post: Le cube devient sélectionnable
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "CUBE")
        {
            Debug.Log(">>> cube "+other.gameObject.name+" sélectionnable !");
            cube = other.gameObject;
            cube.GetComponent<EtatCubeTP3>().estSelectionnable = true;
        }
    }

    //-------------------------------------------
    // La pince Otool n'est plus en collision avec un objet de TAG CUBE
    // Post: Le cube n'est plus sélectionnable
    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "CUBE")
        {
            Debug.Log(">>> cube " + other.gameObject.name + " n'est plus sélectionnable !");
            cube = other.gameObject;
            cube.GetComponent<EtatCubeTP3>().estSelectionnable = false;
            cube = null;
        }
    }

}
