I don’t understand what I am doing wrong, and why, but when I do CancelInvoke inside Update, its still executing, i can still hear the audio, and transformations.
using UnityEngine;
using Random = UnityEngine.Random;
public class TelephoneBooth : MonoBehaviour
{
public AudioClip ringSound;
public AudioSource source;
public bool _isOpen;
void Start()
{
//Open();
}
private void Update()
{
if (_isOpen && !IsInvoking("Open"))
{
Invoke ("Open", 3);
Debug.Log("Invoked");
}
if (!_isOpen && IsInvoking("Open"))
{
CancelInvoke ("Open");
Debug.Log("CANCEL");
}
}
void Open()
{
InvokeRepeating("Ring", 0, 3.0f);
InvokeRepeating("ShakeThePhone", 0, 0.1f);
}
void Ring()
{
source.PlayOneShot(ringSound);
}
void ShakeThePhone()
{
transform.localScale = new Vector2(1f, Random.Range(0.1f, 0.3f)+1f );
}
}