So basically I’m trying to cancel an InvokeRepeating call from another script using this code:
void OnTriggerExit(Collider otherCollider) {
if (otherCollider.tag == "Player") {
CancelInvoke ("Approached");
But the cancel Invoke doesn’t cancel it.
This is the invoke I am trying to cancel:
using UnityEngine;
using System.Collections;
public class EnemyAi : MonoBehaviour {
public Transform target;
public Transform myTransform;
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
}
void Approaching () {
transform.LookAt (target);
transform.Translate (Vector3.forward * 1 * Time.deltaTime);
anim.SetInteger ("EnemyState", 1);
}
public void Attack () {
anim.SetInteger ("EnemyState", 2);
CancelInvoke ("Approached");
}
public void Approached () {
InvokeRepeating ("Approaching", 0.01f ,0.01f);
}
,