Can't activate my timer for shooting script?

I have two scripts, I’m attempting to make my first script use a timer (my second script) and I’m not very good at referencing so I decided to try it out and understand it better. so I created the first script and as far as I can tell, in my second script the timer should be counting down since the console is returning the Debug.Log (“true”); however the tickbox for public bool IsTiming; is set to true once I have started? I’m pretty new to c# so probably just a noob problem :confused:

using System.Collections;

public class WeaponFireattempt2 : MonoBehaviour 
{
	public float bullets = 7f;
	public GameObject deagle;
	public bool animationreloadplayed = false;
	public bool fired = false;
	public float Distance;
	public float MaxDistance = 100;
	public float Damage = 25;
	public bool Reloading = false;
	public bool timedown;
	public float time = .75f;
	public bool firedshot = false;
	public bool haswaited = false;

	void Start ()
	{
	}
	// Update is called once per frame
	void Update () 
	{
		if (Input.GetButtonDown ("Fire1") && animationreloadplayed == false)
		{
			firedshot = true;
			fired = true;
		}
		if (bullets <= 0f && bullets < 7)
		{
			animationreloadplayed = true;
		}
		if (fired == true)
		{
			RaycastHit hit;
			{
				if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.down), out hit))
				{
					Distance = hit.distance;
					if (Distance < MaxDistance)
					hit.transform.SendMessage ("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
					Debug.DrawLine(transform.position, hit.point, Color.red);
					fired = false;
				}
			}
		}
		if (Input.GetKeyDown (KeyCode.R))
		{
			animationreloadplayed = true;
		}
		if (animationreloadplayed == true)
		{
			deagle.animation.Play ("Reload");
			bullets = 7f;
			if (bullets == 7 && animationreloadplayed == true)
			{
				animationreloadplayed = false;
			}
		}
		if (firedshot == true)
		{
			transform.SendMessage ("beginTimer");
			if (haswaited == true)
			{
				bullets = bullets -1f;
				deagle.animation.Play ("Fire");
				firedshot = false;
				audio.Play ();
				haswaited = false;
			}
		}
	}
}

Second script

using UnityEngine;
using System.Collections;

public class Force : MonoBehaviour
{
	public float timer = 0f;
	public bool IsTiming = false;
	public float NumberOfSecondsToWait = 1f;
	public GameObject deagle;

	void beginTimer()
	{
		timer = 0f;
		IsTiming = true;
		if(IsTiming == true)
		{
			
			timer = timer * Time.deltaTime;
			{
			    Debug.Log ("true");
			}
		}
		if (timer < NumberOfSecondsToWait)
		{
			deagle.GetComponent<WeaponFireattempt2>().haswaited = true;
		}
	}
	
	void EndTimer()
	{
		IsTiming = false;
		timer = 0f;
	}
}

Please watch this [Bucky’s Scope Tutorial][1]. Sorry if my post is long, but it will teach you a great thing about code that you can use later on. When you are trying to access or modify a variable in another class then you need to put the name of that class first so something like this:

using UnityEngine;
using System.Collections;

public class Testing2 : MonoBehaviour {
	public static int NewIntYAY = 1;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Another Class!

using UnityEngine;
using System.Collections;

public class Testing1 : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	//This is how you would change the variable in Testing2 class
		Testing2.NewIntYAY = 5;
	}
}

See how I put Testing2 in front of the variable that I wanted to use, that is how you modify that variable in another class. If it isn’t working it is probably because your variable isn’t static, it has to be static to access it in another class. Also, try using the Update() function instead of making your own if you want something to be checked constantly. Here is your codes fixed:

using UnityEngine;
using System.Collections;

public class wfa2 : MonoBehaviour{
	public float bullets = 7f;
	public GameObject deagle;
	public bool animationreloadplayed = false;
	public bool fired = false;
	public float Distance;
	public float MaxDistance = 100;
	public float Damage = 25;
	public bool Reloading = false;
	public bool timedown;
	public float time = .75f;
	public bool firedshot = false;
	public static bool haswaited = false;
	
	void Start ()
	{
	}
	// Update is called once per frame
	void Update () 
	{
		if (Input.GetButtonDown ("Fire1") && animationreloadplayed == false)
		{
			firedshot = true;
			fired = true;
		}
		if (bullets <= 0f && bullets < 7)
		{
			animationreloadplayed = true;
		}
		if (fired == true)
		{
			RaycastHit hit;
			{
				if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.down), out hit))
				{
					Distance = hit.distance;
					if (Distance < MaxDistance){
						hit.transform.SendMessage ("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
					Debug.DrawLine(transform.position, hit.point, Color.red);
					fired = false;
					}
				}
			}
		}
		if (Input.GetKeyDown (KeyCode.R))
		{
			animationreloadplayed = true;
		}
		if (animationreloadplayed == true)
		{
			deagle.animation.Play ("Reload");
			bullets = 7f;
			if (bullets == 7 && animationreloadplayed == true)
			{
				animationreloadplayed = false;
			}
		}
		if (firedshot == true)
		{
			Debug.Log("Fired Shot!");
			Force.IsTiming = true;
			if (haswaited == true)
			{
				bullets = bullets -1f;
				deagle.animation.Play ("Fire");
				firedshot = false;
				audio.Play ();
				haswaited = false;
				Debug.Log("I have waited!");
			}
		}
	}
}

Next Code!

using UnityEngine;
using System.Collections;

public class Force : MonoBehaviour
{
	public static bool IsTiming = false;
	public float NumberOfSecondsToWait = 1f;
	public float TotalTime = 0f;
	
	void Update()
	{
		if(IsTiming == true)
		{
			TotalTime += Time.deltaTime;
			Debug.Log ("Timing!");
		}
		if (TotalTime >= NumberOfSecondsToWait)
		{
			wfa2.haswaited = true;
			IsTiming = false;
			TotalTime = 0f;
		}
	}
}

If you have any problems or this didn’t achieve what you wanted just add a comments, and I will help you modify the code to your needs. :D.
[1]: Buckys C++ Programming Tutorials - 29 - Unary Scope Resolution Operator - YouTube

first of all sorry for the late reply I was studying for exams

Okay, so I understand now what I had to do. I had tried this method but I didn’t realise what the “static” meant. I do now anyway so I understand how this all works but I’m having an issue where I can fire while the reloading animation is playing causing the reloading animation to freeze the gun halfway out. So basically the slider is still back and the clip is still out of the gun. I tried to use this timer to build a similar way around this by doing this. I commented things out next to it to show what I was trying to do. anyway here.

First script
using UnityEngine;
using System.Collections;

public class wfa2 : MonoBehaviour
{
	public float bullets = 7f;
	public GameObject deagle;
	public bool animationreloadplayed = false;
	public bool fired = false;
	public float Distance;
	public float MaxDistance = 100;
	public float Damage = 25;
	public bool Reloading = false;
	public bool timedown;
	public float time = .84f;
	public bool firedshot = false;
	public static bool haswaited = false;
	public static bool haswaited2 = false;
	public static bool Reloadinggun = false;
	
	void Start ()
	{

	}
	// Update is called once per frame
	void Update ()
	{
		if (Input.GetButtonDown ("Fire1") && Reloadinggun == false)// && Reloadinggun == false was added so that if it is true then this should not work meaning when the timer is working I shouldn't be able to fire?
		{
			firedshot = true;
			fired = true;
		}
		if (bullets <= 0f && bullets < 7)
		{
			animationreloadplayed = true;
			Force2.IsTiming2 = true;
		}
		if (fired == true)
		{
			RaycastHit hit;
			{
				if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.down), out hit) && haswaited == true)
				{
					Distance = hit.distance;
					if (Distance < MaxDistance)
					{
						hit.transform.SendMessage ("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
						Debug.DrawLine(transform.position, hit.point, Color.red);
						fired = false;
					}
				}
			}
		}
		if (Input.GetKeyDown (KeyCode.R))
		{
			animationreloadplayed = true;
			Force2.IsTiming2 = true;
		}
		if (animationreloadplayed == true && haswaited2 == true)
		{
			deagle.animation.Play ("Reload");
			bullets = 7f;
			Force2.IsTiming2 = false;
			if (bullets == 7)
			{
				animationreloadplayed = false;
			}
		}
		if (firedshot == true && animationreloadplayed == false)
		{
			Debug.Log("Fired Shot!");
			Force.IsTiming = true;
			if (haswaited == true)
			{
				bullets = bullets -1f;
				deagle.animation.Play ("Fire");
				firedshot = false;
				audio.Play ();
				haswaited = false;
				Debug.Log("I have waited!");
			}
		}
	}
}

Second script

using UnityEngine;
using System.Collections;

public class Force2 : MonoBehaviour
{
	public float NumberOfSecondsToWait = 2f;
	public float TotalTime = 0f;
	public GameObject deagle;
	public static bool IsTiming2 = false;

	
	void Update()
	{
		if(IsTiming2 == true)
		{
			wfa2.Reloadinggun = true;//Now the timer has started, this is true meaning I should not be able to fire because if (Input.GetButtonDown ("Fire1") && Reloadinggun == false)
			TotalTime += Time.deltaTime;
			Debug.Log ("Timing2!");
		}
		if (TotalTime >= NumberOfSecondsToWait)
		{
			wfa2.haswaited2 = true;
			IsTiming2 = false;
			TotalTime = 0f;
			wfa2.Reloadinggun = false;//after waiting this is false again so the gun should be able to fire now?
		}
	}
}

I tried to explain this the best I can here is an image to hopefully help you understand the gun is halfway through the reload animation so when it fires it gets caught here and you have a gun frozen like this. Thank you so much for your help by the way you did solve my question I was just hoping you could help me with this before I mark it as solved