- Home /
Question by
RealEfrain12 · Dec 27, 2020 at 08:24 AM ·
c#2d animation2d camera
Shake Effect isn't working
I have a timer script, and when it reaches 0 it will play a shake animation on the main camera, and my issue is that whenever it reaches 0 the first time the random animation is called it will play perfectly fine but after that it's a matter of just play please 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)