Code : Tout sélectionner
public static T[] ShuffleArray<T>(T[] array, int seed)
{
// Cette méthode renvoie un tableau mélangé selon l'algorithme de Fisher-Yates.
}
Code : Tout sélectionner
public static T[] ShuffleArray<T>(T[] array, int seed)
{
// Cette méthode renvoie un tableau mélangé selon l'algorithme de Fisher-Yates.
}
Code : Tout sélectionner
void affichertexteporter()
{
text_interaction_porter.GetComponent<Text>().enabled = true;
}
void enlevertexteporter()
{
text_interaction_porter.GetComponent<Text>().enabled = false;
}
void affichertexteramasser()
{
text_interaction_ramasser.GetComponent<Text>().enabled = true;
}
void enlevertexteramasser()
{
text_interaction_ramasser.GetComponent<Text>().enabled = false;
}
Code : Tout sélectionner
//Afficher le Text _texte par défaut ou le masquer
void AfficherTexte (Text _texte, bool _afficher = true)
{
_texte.enabled = _afficher;
}
Code : Tout sélectionner
void Awake ()
{
// Récupérer les components Text
textePorter = text_interaction_porter.GetComponent<Text>();
texteRamasser = text_interaction_ramasser.GetComponent<Text>();
}
void Start()
{
// Masquer les Texts
AfficherTexte (textePorter, false);
AfficherTexte (texteRamasser, false);
}
Code : Tout sélectionner
// Ramasser ou Lacher l'objet en fonction de _ramasser
void RamasserObjet (bool _ramasser)
{
game_object_touched.GetComponent<Rigidbody>().isKinematic = _ramasser;
game_object_touched.transform.parent = _ramasser ? player.transform : null;
porter = _ramasser;
}
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ramassage : MonoBehaviour
{
public GameObject game_object_touched;
bool porter;
public GameObject text_interaction_porter;
public GameObject text_interaction_ramasser;
public GameObject player;
public int nombre_de_cubes;
private Text texteRamasser = null;
private Text textePorter = null;
void Awake ()
{
// Récupérer les components Text
textePorter = text_interaction_porter.GetComponent<Text>();
texteRamasser = text_interaction_ramasser.GetComponent<Text>();
}
void Start()
{
// Masquer les Texts
AfficherTexte (textePorter, false);
AfficherTexte (texteRamasser, false);
}
// Update is called once per frame
void Update()
{
RaycastHit hit;
Debug.DrawRay(transform.position, transform.forward * 3, Color.red);
if (Physics.Raycast(transform.position, transform.forward , out hit, 3))
{
game_object_touched = hit.transform.gameObject;
}
else
{
game_object_touched = null;
}
if (game_object_touched != null)
{
if (game_object_touched.tag == "Ramassable")
{
if (porter)
AfficherTexte (textePorter, false);
else
AfficherTexte (texteRamasser);
if (Input.GetKeyDown(KeyCode.E))
{
RamasserObjet (!porter);
}
}
else
{
if(game_object_touched.tag == "Cube")
{
AfficherTexte (texteRamasser, !porter);
if (Input.GetKeyDown(KeyCode.E) && !porter)
{
collect();
nombre_de_cubes += 1;
AfficherTexte (texteRamasser, porter);
}
}
}
}
}
void collect()
{
game_object_touched.SetActive(false);
}
// Ramasser ou Lacher l'objet en fonction de _ramasser
void RamasserObjet (bool _ramasser)
{
game_object_touched.GetComponent<Rigidbody>().isKinematic = _ramasser;
game_object_touched.transform.parent = _ramasser ? player.transform : null;
porter = _ramasser;
}
//Afficher le Text _texte par défaut ou le masquer
void AfficherTexte (Text _texte, bool _afficher = true)
{
_texte.enbaled = _afficher;
}
}