Animations do not start - What did I wrong?

I ask myself what I did wrong. The second animations by pressing ‘e’ work but the others do not. The others do not start at all.

This script is for the FPS controller. All objects are filled in.
For example the ‘BuggyDoorLeft1’ GameObject has its animation attached, which I want to get via code.
The objects are from one model which I have created with Cinema 4D. The fbx structure is hierarchic like.

Object
_Object1
__BuggyDoorLeft1
___ Mesh …
___Mesh …

I marked the animations as ‘Legacy’ too. The objects got the ‘animation’ component with an array and the attached animation. I received no error.

    public GameObject BuggyDoorLeft1;
    public GameObject BuggyDoorRight1;
    private bool BuggyDoorReverse = false;

    public GameObject BuggyStarter;
    private bool BuggyStartReverse = false;
    public GameObject BuggyItself;

    public GameObject GrandDoorUp;
    public GameObject GrandDoorDown;
    private bool GrandDoorReverse = false;


    // Use this for initialization
    void Start ()
    {
   
    }

    // Update is called once per frame
    void Update()
    {

        if (Vector3.Distance(transform.position, BuggyStarter.transform.position) <= 200 )
        { 
            if (Input.GetKey(KeyCode.T))
            {
               
               Debug.Log("condition fulfilled");               

                if (BuggyDoorReverse == true)
                {
                    var b = BuggyDoorLeft1.GetComponent<Animation>();
                    b["DoorLeft"].speed = -1;
                    b.Play("DoorLeft");
                  
                    var d = BuggyDoorRight1.GetComponent<Animation>();
                    d["DoorRight"].speed = -1;
                    d.Play("DoorRight");

                    BuggyDoorReverse = !BuggyDoorReverse;                            
                }


                if (GrandDoorReverse == false)
                {
                    var c = GrandDoorUp.GetComponent<Animation>();
                    c["DoorUp"].speed = (GrandDoorReverse == false ? 1f : -1f);
                    c.Play("DoorUp");

                    var e = GrandDoorDown.GetComponent<Animation>();
                    e["DoorDown"].speed = (GrandDoorReverse == false ? 1f : -1f);
                    e.Play("DoorDown");
                    GrandDoorReverse = !GrandDoorReverse;
                }

                var a = BuggyItself.GetComponent<Animation>();
                a["BuggyDrive"].speed = (BuggyStartReverse == false ? 1f : -1f);
                a.Play("BuggyDrive");

                var y = BuggyStarter.GetComponent<Animation>();
                y["SwitchDrive"].speed = (BuggyStartReverse == false ? 1f : -1f);
                y.Play("SwitchDrive");
                BuggyStartReverse = !BuggyStartReverse;
            }
        }


        if (Vector3.Distance(transform.position, BuggyDoorLeft1.transform.position) <= 200 || Vector3.Distance(transform.position, BuggyDoorRight1.transform.position) <= 200)
        {
            if (Input.GetKey(KeyCode.E))
            {
                var a = BuggyDoorLeft1.GetComponent<Animation>();

                a["DoorLeft"].speed = (BuggyDoorReverse == false ? 1f : -1f);
                a.Play("DoorLeft");

                var d = BuggyDoorRight1.GetComponent<Animation>();
                d["DoorRight"].speed = (BuggyDoorReverse == false ? 1f : -1f);
                d.Play("DoorRight");

                BuggyDoorReverse = !BuggyDoorReverse;
            }
        }

i see some “strange” condition wich makes me think : "why want this guy hold down “t” the whole time?.
The code in the if block starting at line 28 is executing only when the key “t” is HOLD down, if you press it only once and release it the debug message appears but the block isnt executed anymore the next frames.

true, but it wouldn’t stop the animations from occuring once the button was released, it would probably reset them to their start every frame the button was held down though. Generally you’d use the “isPlaying” attribute in the conditionals to check to see if the animation was already playing for things like this.

Thanks for the answers. I tried to set the time to 0.0f. All isPlaying(“TheAnimation”) returned true. Using this on Start() without setting the speed and the time for testing, the animations did not start.

The next step was to get the difference between the animation which is played correctly and the one which failed. I wrote two classes to get the differences of the properties via System.Reflections on the first level. Maybe it is useful for others too.

public class TestComparison
{
    public String Name = "";
      
    public System.Object TheProperty;
}

public static class Differences
{
    public static List<System.Object> GetDifferences(System.Object A, System.Object B)
    {
        //List<dynamic> ListA = new List<System.Object>();
        //List<dynamic> LIstB = new List<System.Object>();

        List<TestComparison> ListA = new List<TestComparison>();
        List<TestComparison> ListB = new List<TestComparison>();

        foreach (var a in A.GetType().GetProperties())
        {
            TestComparison TA = new TestComparison();
            TA.Name = a.Name;
            TA.TheProperty = a.GetValue(A, null);
            ListA.Add(TA);
            //ListA.Add(a.GetValue(A, null));
        }

        foreach (var b in B.GetType().GetProperties())
        {
            TestComparison TB = new TestComparison();
            TB.Name = b.Name;
            TB.TheProperty = b.GetValue(B, null);
            ListB.Add(TB);
        }


        List<System.Object> Differences = new List<System.Object>();


        foreach (var x in ListA)
        {
            var y = ListB.Where(z => z.Name.ToUpper().Trim() == x.Name.ToUpper().Trim());

            if (y.Count() >= 1)
            {
             
                if (y.ElementAt(0).TheProperty.ToString() != x.TheProperty.ToString())
                {
                    Differences.Add(x);
                    Differences.Add(y.ElementAt(0));
                }
            }
            else
            {
                Differences.Add(x);
            }

        }


        foreach (var x in ListB)
        {
            var y = ListA.Where(z => z.Name.ToUpper().Trim() == x.Name.ToUpper().Trim());

            if (y.Count() <= 0)
            {
                Differences.Add(x);
            }
        }

        return Differences;

    }

}

And the calls:

        var r = GrandDoorUp.GetComponent<Animation>();
        var s = BuggyDoorLeft1.GetComponent<Animation>();
        var Result = Differences.GetDifferences(r["DoorUp"], s["DoorLeft"]);

I did not find a real difference.