Question by
RealEfrain12 · Dec 27, 2020 at 08:19 AM ·
c#animationrandom2d camera
Animations On Random isn't working
So I added a timer that when it reaches 0 it will play a shake animation, but I'm having an issue where it will play perfectly fine on the 1st time it gets called, but after a while it will barely or never play again. Here is my Timer Script: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ShakeTimer : MonoBehaviour { public float timeShake = 12f; public bool isTime = false; public ShakeEffect shake;
void Start()
{
isTime = true;
timeShake = 12f;
shake = GameObject.FindGameObjectWithTag("ScreenShake").GetComponent<ShakeEffect>();
}
void Update()
{
if (isTime)
{
if (timeShake > 0)
{
timeShake -= Time.deltaTime;
}
else
{
shake.Shake();
timeShake += 12;
}
}
}
}
Here is my Shake Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShakeEffect : MonoBehaviour
{
public Animator camAnim;
public void Shake()
{
int rand = Random.Range(0, 3);
if (rand == 0)
{
camAnim.SetTrigger("Shake");
Debug.Log("1");
}
else if (rand == 1)
{
camAnim.SetTrigger("Shake2");
Debug.Log("2");
}
else if (rand == 2)
{
camAnim.SetTrigger("Shake3");
Debug.Log("3");
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613022230im_/https://answers.unity.com/themes/thub/images/avi.jpg)