Call script in random (time) and loop

Hello guys I have a problem and I don’t know how to do…I hope in the help of someone: I created a script for the shake shake. I would like this script (see attachment) to be repeated in time to random (time) and loop. I assume I have to call it with another script but I don’t know how to do? thanks to everyone.

This is the code of Shakecamera:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class playshake : MonoBehaviour
{
    public float power = 0.7f;
    public float duration = 1.0f;
    public Transform cameraa;
    public float slowdown;
  
  

    Vector3 startposition;
    float initialduration;

    void Start()
    {
        cameraa = Camera.main.transform;
        startposition = cameraa.localPosition;
        initialduration = duration;
    }



  public   void shake()
    {
    
            if (duration>0)
            {
                cameraa.localPosition = startposition + Random.insideUnitSphere * power;
                duration -= Time.deltaTime * slowdown;

            StartCoroutine(LateCall());
        }

        IEnumerator LateCall()
        {

            yield return new WaitForSeconds(2);


            duration = initialduration;
                cameraa.localPosition = startposition;
            }
        }
    }

I came into this thread wondering whether the piece you were missing was how to make random numbers or how to use Unity coroutines, and was surprised to find that you apparently already know both of those. I would have thought that this was a pretty easy problem given those tools.

Write a coroutine…that contains a loop…that contains a wait…that uses a random number for the length of the wait.

1 Like