I am attempting to call an animation state for walls to disintegrate once a level is completed. This is the code that is held on the walls themselves:
public class Wallblink : MonoBehaviour
{
public static Wallblink instance;
public Animator wallAnim;
private void Awake()
{
instance = this;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.M))
{
PlayWallAnim();
}
}
public void PlayWallAnim()
{
wallAnim.Play("WallBlink");
}
}
I have the test keycode in the update function and when the key is pressed it works as it should and how I want it too. If I try to call the function from another script it is as if it was never called. Why is this? If I reference the script through instance it does not work, if I grab the script in runtime it does not work. This is what I currently have and it still does not work:
var walls = GameObject.FindGameObjectsWithTag("Wall");
foreach (var wall in walls)
{
wall.GetComponent<Wallblink>().PlayWallAnim();
}
Does anyone have any ideas on how I could go about this or fix an issue I have here? Yes, the walls have the tag Wall.