In here i have 2 objects and once 1stobjects.x is bigger, once smaller than 2nd object. I want to change animation of 2ndobject if first objects.x is bigger. I wrote the script which in my opinion is quite good… But only in my opinion… in Unity from starting the game all 2ndobjects start with allready set animation… I cant figur it out what’s wrong
( i changed floats and GameObjects from my language to some random to make it easier…)
Animator animator;
float 1stobjectsx;
float 2ndobjectxs;
void Start () {
animator = GetComponent();
GameObject[ ] car= GameObject.FindGameObjectsWithTag (“porshe”);
GameObject[ ] bike = GameObject.FindGameObjectsWithTag (“bmx”);
foreach (GameObject porshe in car) {
1objectsx = porshe.transform.position.x;
}
foreach (GameObject bmx in bike) {
2ndobjectsx = bmx.transform.position.x;
}
if (1stobjectsx >= 2ndobjectsx) {
animator.SetBool (“bool”, true);
}
else if(1stobjectsx <= 2ndobjectsx){
animator.SetBool(“bool”, false);}
}
void Update () {
if( 1stobjectsx > 2ndobjectsx){
animator.SetBool(“bool”, true);}
if(1stobjectsx < 2ndobjectsx){
animator.SetBool(“bool”, false);}
}
}