shaking camera in c#

106

shaking camera in c# -

public IEnumerator Shake(float duration, float magnitude)
{
        Vector3 orignalPosition = transform.position;
        float elapsed = 0f;

        while (elapsed < duration)
        {
                float x = Random.Range(-1f, 1f) * magnitude;
                float y = Random.Range(-1f, 1f) * magnitude;

                transform.position = new Vector3(x, y, -10f);
                elapsed += Time.deltaTime;
                yield return 0;
        }
        transform.position = orignalPosition;
}
// this is coroutine function if you want to run it use the code below
// StartCoroutine(cameraShake.Shake(3f, 0.4f));

Comments

Submit
0 Comments