- Home /
Question by
ShiNoKitsune · Oct 24, 2017 at 03:27 PM ·
animationanimatortriggers
Problem with Animation triggring
I'm trying to make the player play the Organ and it works fine but when I press the button to get out of the sit, insted of the player play the animation "Sit to Stand" and after stay in Idle, it goes to Idle and immediately starts "Walking" animation Again! How can I stop that?
.
Scritp to Play the musical Organ:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayOrgao : MonoBehaviour {
public GameObject Char;
Animator Animat;
bool isWakingTo;
bool sittingOn=false;
public AudioSource Music;
public GameObject Trigger;
// Use this for initialization
void Start () {
Animat = Char.GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
//I Think Here is the problem
if (!sittingOn && Trigger.GetComponent<PlayOrgao>().enabled == true ) {
Animat.SetTrigger ("Walk");
isWakingTo = true;
}
if (isWakingTo){
Vector3 targetDir;
targetDir = new Vector3 (transform.position.x - Char.transform.position.x, 0f, transform.position.z - Char.transform.position.z);
Quaternion rot = Quaternion.LookRotation (targetDir);
Char.transform.rotation = Quaternion.Slerp (Char.transform.rotation, rot, 0.05f);
Char.transform.Translate (Vector3.forward * 0.05f);
if(Vector3.Distance(Char.transform.position,this.transform.position)<1f){
Animat.SetTrigger ("Siting");
Char.transform.rotation = this.transform.rotation;
isWakingTo = false;
sittingOn = true;
}
}
}
}
Script That Triggers the Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayOrgao : MonoBehaviour {
public GameObject Char;
Animator Animat;
bool isWakingTo;
bool sittingOn=false;
public AudioSource Music;
public GameObject Trigger;
// Use this for initialization
void Start () {
Animat = Char.GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (!sittingOn && Trigger.GetComponent<PlayOrgao>().enabled == true ) {
Animat.SetTrigger ("Walk");
isWakingTo = true;
}
if (isWakingTo){
Vector3 targetDir;
targetDir = new Vector3 (transform.position.x - Char.transform.position.x, 0f, transform.position.z - Char.transform.position.z);
Quaternion rot = Quaternion.LookRotation (targetDir);
Char.transform.rotation = Quaternion.Slerp (Char.transform.rotation, rot, 0.05f);
Char.transform.Translate (Vector3.forward * 0.05f);
if(Vector3.Distance(Char.transform.position,this.transform.position)<1f){
Animat.SetTrigger ("Siting");
Char.transform.rotation = this.transform.rotation;
isWakingTo = false;
sittingOn = true;
}
}
}
}
Here the Animator Controle:
animator.png
(41.4 kB)
Comment
By do way I want to play a music after the "Stand to Sit" animation is finish if someone help me with that and with this :http://answers.unity3d.com/questions/1421791/how-do-i-can-make-this-3rd-person-camera-smoother.html
Thanks for the attention xd