Calling function from another script won't work !

Hello everyone, and thanks in advance for reading this post :). So as the title states, I am trying to call a function from another script, but it won’t work. The story behind it is:

When the player walks into a trigger zone(set up in a room, in a house), the code will check whether the door that leads to that room has been closed or not. If it hasn’t been closed(by the player), the door will close on it’s own.

I have an universal script placed on every door in the house, wich opens and closes the doors using rotations, and it works just fine :). But when I try to call that method/function from the script placed on the trigger zone(represented by a cube with no mesh filter, therefor the cube isn’t visible, but the box collider is still there and will interact with the player) it won’t work. Here are the scripts:

The one placed on the trigger zone(the GameObject Door is assigned in the inspector, and yes I am 140% sure I assigned the correct door, since I even used a print message in the script, and the message will print, but the method won’t call, look below :P):

using UnityEngine;
using System.Collections;

public class TriggerZone1 : MonoBehaviour
{
	public AudioSource CreepyDoor;
	public GameObject Door;
	private GameObject SwingChair;
	private GameObject Tape2;
	private int EventTriggered;
	private int DoorKnock;
	void Start()
	{
		SwingChair=GameObject.Find ("/SwingChair");
		Tape2=GameObject.Find ("/TapeRecorder2");
		EventTriggered=0;
		DoorKnock=0;
	}
	void Update()
	{
		if(EventTriggered==1)
		{
			if(SwingChair.audio.isPlaying)
				if(!SwingChair.animation.isPlaying)
				{
					if(Door.GetComponent<OpenDoor>().doorState==2)
					{
						print ("NYAN CAT");//yes, this message actually prints, and doorState==2 means the door is opened
						Door.GetComponent<OpenDoor>().DoorRotation();//this is where I try to call the function but it won't work
					}
					SwingChair.animation.Play();
				}
			if(!SwingChair.audio.isPlaying)
			{
				if(SwingChair.animation.isPlaying)
				{
					SwingChair.animation.Stop();
					CreepyDoor.Play();
					DoorKnock=1;
				}
			}
			if(DoorKnock==1)
			{
				if(!CreepyDoor.isPlaying)
				{
					Door.GetComponent<OpenDoor>().IsLocked=0;
					DoorKnock=2;
				}
			}
					
		}
	}
	void OnTriggerEnter()
	{
		if(Tape2==null)
		{
			if(EventTriggered==0)
			{
				SwingChair.animation.Play();
				SwingChair.audio.Play ();
				EventTriggered=1;
				Door.GetComponent<OpenDoor>().IsLocked=1;
			}
		}
	}
}

And here is the script placed on every door inside the house( I know the script might look a bit odd, I might consider rewriting it later on when my game will be ready to be released, but the thing is that no matter what, the way I tried to call the function is the way I’ve seen in other topics, and the one pictured in Unity’s DOCS, and it won’t work. Also the function will work perfectly when Invoked in this script):

using UnityEngine;
using System.Collections;

public class OpenDoor : MonoBehaviour 
{
	public AudioSource audio1;
	public AudioSource audio2;
	public AudioSource audio3;
	private GameObject Player;
	private Transform PlayerT;
	private int openAngle;
	public int doorState;
	private float RotateY;
	public int IsLocked;
	public static int LockedMessage;
	void Start()
	{
		LockedMessage=0;
		openAngle=-1;
		doorState=0;
		Player=GameObject.Find ("/Player");
		PlayerT=Player.transform;
		RotateY=transform.rotation.eulerAngles.y;
		Invoke ("DoorRotation",0.04f);
	}
	void Update()
	{
		if(openAngle<0)
			if(openAngle!=-1)
			{
				openAngle=-1;
				audio2.Play ();
			}
		if(openAngle==-1)
			if(doorState!=0)
				doorState=0;
		if(openAngle==92)
			if(doorState!=2)
				doorState=2;		
	}
	void OnMouseDown()
	{
		if(Vector3.Distance(PlayerT.position,transform.position)<=5.0f)
		{
			if(IsLocked==0)
			{
				if(!audio.isPlaying)
					if(doorState==0)
						audio1.Play();
				if(openAngle==-1)
					openAngle=0;
				if(openAngle==92)
					openAngle=88;
				if(doorState==0)
					doorState=1;
			}
			else
			{
				LockedMessage=1;
				if(!audio3.isPlaying)
					audio3.Play();
				Invoke ("DoorMessage",2.0f);
			}
		}
	}
	void OnMouseEnter()
	{
		if(Vector3.Distance(PlayerT.position,transform.position)<=7.5f)
			Screen.showCursor=true;
	}
	void OnMouseExit()
	{
		Screen.showCursor=false;
	}
	public void DoorRotation()//obviusly, this is the method I am trying to call, but it won't work if I am calling it from a different script
	{
		if(openAngle>=0&openAngle<92)
		{
    		if(doorState==1)
			{
				openAngle+=4;
				RotateY+=4.0f;
				transform.eulerAngles=new Vector3(transform.eulerAngles.x,RotateY,transform.eulerAngles.z);
			}
			if(doorState==2)
			{	
				openAngle-=4;
				RotateY-=4.0f;
				transform.eulerAngles=new Vector3(transform.eulerAngles.x,RotateY,transform.eulerAngles.z);
			}
		}
		Invoke("DoorRotation",0.04f);
	}
	void DoorMessage()
	{
		LockedMessage=0;
	}
}

So yeah, thanks in advance for any answers, I am out of ideas, I’ve tried answers I’ve seen in other topics and they didn’t work, so what now ? Please help me :(.

I’d put a debug.log to see what openAngle at the very beginning of that DoorRotation function (before everything else in it), you use “openAngle = -1” in your script alot, i suspect you’re logic works because the mouse click version is settings that to something other than -1 and then that if in DoorRotation evaluates to true… when it’s being called from a script something has been missed and it’s still -1 so it’s evaluating to false and not doing anything.

Yes, you were right, I can’t believe how blind I was, thank you very much for your answer, I shouldn’t have created this topic, I should have studied the problem in a deeper way, but now it’s fixed, thank you :).

no worries, when you’re eyeballs deep in it you can sometimes not see things :slight_smile: