I'm playing some animations through a C# script. In such script, I'm not using any other methods except GetComponent<Animation>()
and Play()
. The animations are of opening/closing car doors and are being played from separate, different functions.
When I open a new door, the last opened door goes back to its default state of being closed. How can I stop that from occurring? I want the doors to stay open until I close them again.
All doors and animations belong to a single object, which is a car model made by my coworker. It has one joint bone for each door. There's no skinned mesh renderer component.
Here's one of the functions:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class handle : MonoBehaviour
{
public GameObject Car;
private Animation anima;
public bool bootspaceAnim = false;
void Start()
{
anima = Car.GetComponent<Animation>();
}
public void bootspaceHandle()
{
if (bootspaceAnim == false)
{
anima.Play("Bootspace_Anim");
anima["Bootspace_Anim"].speed = 1.0f;
anima["Bootspace_Anim"].time = 0;
bootspaceAnim = true;
}
else
{
anima.Play("Bootspace_Anim");
anima["Bootspace_Anim"].speed = -1.0f;
anima["Bootspace_Anim"].time = anima["Bootspace_Anim"].length;
bootspaceAnim = false;
}
}
}
Car.GetComponent<Animation>();
is not returning the same for each of your scripts. \$\endgroup\$