AIController.OnTriggerStay2D C# (CSharp) Method

OnTriggerStay2D() protected method

protected OnTriggerStay2D ( Collider2D other ) : void
other UnityEngine.Collider2D
return void
	protected virtual void OnTriggerStay2D (Collider2D other)
	{
		if (other.tag == "Wall") 
		{
			RaycastHit2D raycast = Physics2D.Raycast (transform.position, moveDir);
			if (raycast.collider != null && raycast.collider.tag == "Wall") 
			{
				float distance = Vector2.Distance (transform.position, raycast.point);
				if (distance < 1.5f)
					nearWall = true;
				else
					nearWall = false;
			}
		} 
		//else if (other.tag == "Player") 
		else if (other.gameObject.Equals(getPlayer())) 
		{
			if (panicked) 
			{
				//timePanicked = panicCooldownSeconds;
				return;
			}

			if (alertLevel >= alertThreshold) 
			{
				//Debug.Log("ALERTED");
				alert ();
			}

			if (alertLevel >= panicThreshold) 
			{
				//Debug.Log("PANICKED");
                GlobalGameStateManager.PanicTree = GetClosestPlayer(transform.position);

                //GlobalGameStateManager.PanicTree.GetComponent<PossessableTree>().BodyParts.Trunk.GetComponent<SpriteRenderer>().color = Color.red;

				panic ();
			}

			if( getPlayer() != null )
			{
				PossessableTree script = getPlayer ().GetComponent<PossessableTree> ();
				if (script != null && script.Eating) 
				{
					panic ();
				}
			}

			// Increment alertLevel
			increaseAlertLevel (hearingAlertMultiplier);
		}
		if (other.tag.Equals ("PossessorTrigger")) 
		{
			if (panicked || alerted)
				return;

			if (Vector2.Distance (other.gameObject.transform.position, gameObject.transform.position) > (0.5f * GetComponent<CircleCollider2D> ().radius))
				return;

			previousAlertLevel = alertLevel;
			if (previousAlertLevel < alertThreshold) 
			{
				previousAlertLevel = (panicThreshold - alertThreshold) / 4 + alertThreshold;
			}
			alertLevel = panicThreshold - 0.01f;
			alert ();
		}
	}