
using UnityEngine;

namespace WorldPlatforms
{
  public class NonSolidWallScript : MonoBehaviour
	{
		public void InitVars(Texture2D textureSolid, Texture2D textureNonSolid, Renderer renderer)
    {
			this.textureNonSolid = textureNonSolid;
			this.textureSolid = textureSolid;
			this.renderer = renderer;

			renderer.material = new Material(renderer.material)
			{
				mainTexture = textureSolid
			};
		}

		private int inside = 0;
		private Texture2D textureSolid;
		private Texture2D textureNonSolid;
		private Renderer renderer;

		private void OnTriggerEnter(Collider c)
		{
			if (c.gameObject.layer == 8 && c.GetComponent<NetworkView>().isMine)
			{
				if(inside == 0)
        {
					renderer.material = new Material(renderer.material)
					{
						mainTexture = textureNonSolid
					};
				}
				inside++;
			}
		}

		private void OnTriggerExit(Collider c)
		{
			if (c.gameObject.layer == 8 && c.GetComponent<NetworkView>().isMine)
			{
				inside--;
				if (inside == 0)
				{
					renderer.material = new Material(renderer.material)
					{
						mainTexture = textureSolid
					};
				}
			}
		}
	}
}
