360 degree plane rotation & texture change

Hello all,

These forums have been really helpful,
especially Robertbu,with a question I had about switching textures on an upright plane

The plane is rotating 360 degrees around the Y Axis and

The plane switches its texture depending in the angle

but the plane is following a character and only reading 0 to 180 degrees and then back down (even though it is rotating 360 as the player moves around ) ,

so the texture are only going halfway (180deg) and then back down.

here’s the code:

using UnityEngine;
using System.Collections;

public class LookAt3 : MonoBehaviour {
	public Transform player;

	public Texture[] textures;

	//public int numbersDevide360; 

		void Start() 
		player = GameObject.FindGameObjectWithTag("Player").transform;

		void Update() 
	// Plane rotates to face the Player
			Vector3 v3 = player.position - transform.position;
			v3.y = 0.0f;
			transform.rotation = Quaternion.LookRotation(-v3);


	void ChangeTexture()
				Vector3 dir = transform.position - player.position;
				float angle = Mathf.Atan2 (dir.x, dir.z) * Mathf.Rad2Deg;
				//int index = (int)angle / numbersDevide360;
				int index = (int)angle /textures.Length;
				GetComponent<Renderer> ().material.mainTexture = textures [index];

Any ideas?
Thanks in advance

Try this to normalize your angle to 0 to 360:

float angle = Mathf.Atan2 (dir.x, dir.z) * Mathf.Rad2Deg;
if (angle < 0.0f) {
     angle = 360.0 - angle;