-DESCRIPTION : script servant à gérer les Bouttons du menu principal du jeu (nouveau jeu, continuer etc...
-UTILISATION : placer le code dans les Bouttons de la scène, puis insérer les prefabs de chaque boutons dans leur case du script component correspondant
-PROBLÈME : bien que Unity ne me signale aucune erreur sur le code, au lancement du jeu l'objet Selection n'apparaît pas, alors qu'il devrait être visible et placé au niveau du bouton Nouveau Jeu... Du coup lorsque l'on appuie sur flèche du haut, flèche du bas ou la touche action (E), rien ne se passe. Mon code est sûrement extrêmement nul, je suis un total débutant perdu x)
-SCRIPT :
Code : Tout sélectionner
using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;
public class Bouttons : MonoBehaviour
{
public GameObject Selection; //objet de la scene qui se place à côté du bouton sélectionné par le joueur
public GameObject NouveauJeu;
public GameObject Continuer;
public GameObject Options;
public GameObject QuitterLaPartie;
public int highlightButton = 0; //variable de selection
public int pressButton = 0; //variable d'appui sur un bouton
void update()
{
Selection.transform.Translate(200, -200, 0);//position de départ du bouton Sélection, à côté du bouton NouveauJeu
while (Input.GetKey(KeyCode.DownArrow) || Input.GetAxis("Vertical") < 0)
{
highlightButton++;
if (highlightButton == 0)
{
Selection.transform.Translate(0, 0, 0); //l’objet Selection ne doit pas bouger
}
if (highlightButton == 1)
{
Selection.transform.Translate(0, -70, 0); //l’objet Selection descend de 70 unités vers le bas (vers le bouton Continuer)
}
if (highlightButton == 2)
{
Selection.transform.Translate(0, -70, 0);
}
if (highlightButton == 3)
{
Selection.transform.Translate(0, -70, 0);
}
if (highlightButton > 3)
{
highlightButton = 0;
Selection.transform.Translate(0, 210, 0);
}
}
while (Input.GetKey(KeyCode.UpArrow) || Input.GetAxis("Vertical") > 0)
{
highlightButton--;
if (highlightButton == 0)
{
Selection.transform.Translate(0, 0, 0);
}
if (highlightButton == 1)
{
Selection.transform.Translate(0, 70, 0);
}
if (highlightButton == 2)
{
Selection.transform.Translate(0, 70, 0);
}
if (highlightButton == 3)
{
Selection.transform.Translate(0, 70, 0);
}
if (highlightButton < 0)
{
highlightButton = 3;
Selection.transform.Translate(0, -210, 0);
}
}
pressButton = highlightButton;
while (Input.GetKeyDown("E") || Input.GetKeyDown("JoystickButton0"))
{
if (pressButton == 0)
{
NouveauJeu.GetComponent<Animation>().Play("NouveauJeuPress");
ORK.Game.NewGame(true);
}
if (pressButton == 1)
{
Continuer.GetComponent<Animation>().Play("ContinuerPress");
ORK.SaveGame.Load(1);
}
if (pressButton == 2)
{
Options.GetComponent<Animation>().Play("OptionsPress");
// lancer ecran options;
}
if (pressButton == 3)
{
QuitterLaPartie.GetComponent<Animation>().Play("QuitterLaPartiePress");
Application.Quit();
}
}
}
}