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;
}
}
}