Bonjour, je travaille actuellement sur la technologie Hololens de Microsoft en stage. J'ai un projet a réalisé et là je suis bloqué ... En fait j'ai le logo de mon lycée, et à chaque fois qu'on clique dessus, il tourne sur l'axe X et Y à 360° en 1sec, puis une sorte d'affiche publicitaire s'affiche. Ensuite tout ça se fait à l'envers et on recommence. Voyez cela comme un HYPER-MEGA diapo sauf que j'ai un probleme ... L'animation du logo marche très bien mais les affiches ne s'affichent pas. J'ai créé une anim pour chaque affiche (page), voila voila, je vous laisse le code maintenant :
using UnityEngine;
public class TurnLogoR : MonoBehaviour
{
Vector3 originalPosition;
Animator anim;
int page;
// Use this for initialization
void Start()
{
// Grab the original local position of the sphere when the app starts.
originalPosition = this.transform.localPosition;
anim = GetComponent<Animator>();
page = 0;
}
void OnSelect()
{
page++;
if (!anim.GetBool("playanimlogo"))
{
anim.SetBool("playanimlogo", true);
anim.SetBool("playanimpage" + page, true);
}
else if (anim.GetBool("playanimlogo")) {
page = page - 1;
anim.SetBool("playanimlogo", false);
anim.SetBool("playanimpage" + page, false);
}
}
// Called by SpeechManager when the user says the "Reset world" command
void OnReset()
{
//If the sphere has a Rigidbody component, remove it to disable physics.
var rigidbody = this.GetComponent<Rigidbody>();
if (rigidbody != null)
{
DestroyImmediate(rigidbody);
}
// Put the sphere back into its original local position.
this.transform.localPosition = originalPosition;
}
// Called by SpeechManager when the user says the "Drop sphere" command
void OnTurn()
{
// Just do the same logic as a Select gesture.
OnSelect();
}
}
Bon je ne suis pas très fort pour comprendre le problème comme ça à la volée, mais c'est peut-être dans l'animator, un problème avec les transitions, et là apparemment tu lances deux anims en même temps donc si elles ne sont pas sur deux layers différents ça ne peut juste pas fonctionner. Après une fois j'avais essayé sur deux layers mais ça ne fonctionnait pas très bien va savoir pourquoi... Genre les deux animations se jouaient mais qu'une seul apparaissait à l'écran
J'espère que tu trouveras et si oui je serais intéressé si t'as fait avec plusieurs layers.
Oui tout est réglé ! En effet j'ai créer des layers différents pour chaque animations et j'ai donc changer mon code Voilà :
using UnityEngine;
public class TurnLogoR : MonoBehaviour
{
Vector3 originalPosition;
Animator anim;
Animator animPage1;
Animator animPage2;
Animator animPage3;
Animator animPage4;
AudioSource audioChute;
int page;
public GameObject Cube;
public GameObject Cube2;
public GameObject Cube3;
public GameObject Cube4;
public GameObject musicChute;
// Use this for initialization
void Start()
{
// Grab the original local position of the sphere when the app starts.
originalPosition = this.transform.localPosition;
anim = this.GetComponent<Animator>();
animPage1 = Cube.GetComponent<Animator>();
animPage2 = Cube2.GetComponent<Animator>();
animPage3 = Cube3.GetComponent<Animator>();
animPage4 = Cube4.GetComponent<Animator>();
audioChute = musicChute.GetComponent<AudioSource>();
page = 0;
}
void OnSelect()
{
page++;
if (!anim.GetBool("playanimlogo"))
{
anim.SetBool("playanimlogo", true);
if (page == 1)
{
animPage1.SetBool("playanimpage1", true);
}
else if (page == 2){
animPage2.SetBool("playanimpage2", true);
}
else if (page == 3)
{
animPage3.SetBool("playanimpage3", true);
}
else if (page == 4)
{
animPage4.SetBool("playanimpage4", true);
}
}
else if (anim.GetBool("playanimlogo")) {
page = page - 1;
anim.SetBool("playanimlogo", false);
if (page == 1)
{
animPage1.SetBool("playanimpage1", false);
}
else if (page == 2)
{
animPage2.SetBool("playanimpage2", false);
}
else if (page == 3)
{
animPage3.SetBool("playanimpage3", false);
}
else if (page == 4)
{
animPage4.SetBool("playanimpage4", false);
if (!this.GetComponent<Rigidbody>())
{
var rigidbody = this.gameObject.AddComponent<Rigidbody>();
rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous;
audioChute.enabled = true;
}
DestroyImmediate(anim);
}
}
}
// Called by SpeechManager when the user says the "Reset world" command
void OnReset()
{
//If the sphere has a Rigidbody component, remove it to disable physics.
var rigidbody = this.GetComponent<Rigidbody>();
if (rigidbody != null)
{
DestroyImmediate(rigidbody);
}
// Put the sphere back into its original local position.
this.transform.localPosition = originalPosition;
page = 0;
audioChute.enabled = false;
}
// Called by SpeechManager when the user says the "Turn" command
void OnTurn()
{
// Just do the same logic as a Select gesture.
OnSelect();
}
}
Je met le sujet en résolu
Animation Unity
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Je met le sujet en résolu