Greetings,
I’m currently developing a game, doing a simple door open/close mechanic upon a trigger event. The method (doorOpen.MoveDoor(“OpenDoor”)) is called in this script:
using UnityEngine;
using System.Collections;
public class BaseButtonDoorOpen : MonoBehaviour {
DoorOpen doorOpen;
// Use this for initialization
void Start () {
GameObject PuzzleOpenDoorObj = GameObject.Find("TopDoor");
doorOpen = PuzzleOpenDoorObj.GetComponent<DoorOpen>();
}
void OnTriggerEnter(Collider coll){
if(coll.gameObject.name == "CubeOpenDoor") {
gameObject.renderer.material.color = Color.red;
//StartCoroutine(doorOpen.OpenDoor());;
doorOpen.MoveDoor("OpenDoor");
}
}
void OnTriggerExit(Collider coll){
if(coll.gameObject.name == "CubeOpenDoor") {
gameObject.renderer.material.color = Color.green;
//StartCoroutine(doorOpen.CloseDoor());;
doorOpen.MoveDoor("CloseDoor");
}
}
}
The OpenDoor() and CloseDoor() methods are called here:
using UnityEngine;
using System.Collections;
public class DoorOpen : MonoBehaviour {
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log("transform.position.y = " + transform.position.y );
}
public void MoveDoor (string func)
{
Debug.Log("InvokeRepeating called");
InvokeRepeating(func, 10, 0f);
}
public void OpenDoor()
{
Debug.Log("Opening door");
speed = 0.5f;
transform.Translate(0, speed * Time.deltaTime ,0);
}
public void CloseDoor()
{
Debug.Log("Closing door");
speed = -0.5f;
transform.Translate(0, speed * Time.deltaTime ,0);
}
}
My problem is that despite passing the right arguments, the InvokeRepeating method is not calling the respective method in its argument.
Any help would be greatly appreciated!