[ExecuteInEditMode()] Problem - Create Instance of Classes

[ExecuteInEditMode()] Problem - Create Instance of Classes

I have script KK when i applied in GUITexure, all my public variables show in inspector windows, everything works correctly, but every time when i hit play button to check myGUI Texture Location. All classes instance create automatically, i have no idea how to solve this problem.

Any help would be appreciated, Thanks

my KK Script here

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Joystick))]
[ExecuteInEditMode()]
public class KK : MonoBehaviour
{
private float GUIalpha = 1.0f;
protected Joystick joystick;
protected GUIStyle noGuiStyle;
private S background;
private L location;

// Use this for initialization
void Awake ()
{ joystick = gameObject.GetComponent();
background = gameObject.AddComponent();
location = gameObject.AddComponent();
}

void Update()
{
if (joystick.IsFingerDown()) {
background.up();

} else {
background.down();
}
if (background.texture != null){
location.updateLocation();
}
}

void OnGUI () {
//GUI.color.a = GUIalpha;
GUI.Box(new Rect(location.offset.x + background.offset.x - background.texture.width/2,location.offset.y + background.offset.y - background.texture.height/2,background.texture.width,background.texture.height),background.texture);
}

}
1470662--80818--$1.jpg

After hit play button

1470662--80819--$2.jpg

look at the awake function. you add components there. i think you could, like the joystick component, just requirecomponent them and process them like the joystick thing.

Thanks for reply
but the problem is my scripting is little confusing,I have four classes, T class, S Class which is inherited from T, another classes L and KK. when I applied S Class to any game Object. all public variables of T class show in inspector window because inherited from T. I created object of S class and L Class in my KK class. i can access all the variables of these classes but variables don’t show in my inspector window. so somebody suggested me to use to access variable of these classes. actually i simply want to make touch joystick control switchable texture. if i touch to joystick texture background up, joystick appears enable and touch end joystick appears disable.

Any help would be appreciated, Thanks

Then whatever you do, appears too complicated for what you intend, atleast to me.
I would do it like that (Pseudo, out of my head):

public enum JoystickDirection { Down, Left, Right.... and so on} //*x

[System.Serializable]
public class JoystickTexture {
 public JoystickDirection direction; //*x
 public Texture2D activeTex;
 public Texture2D inactiveTex;
}

public List<JoystickTexture> texSwap = new List<JoystickTexture();

public Texture2D GetStateTexture(JoystickDirection dir, bool isActive) { //*x
 for(int i=0;i<texSwap.Count;i++){
  if (texSwap[i].direction == dir){ //*x
   return isActive == true ? texSwap[i].activeTex : texSwap[i].inactiveTex;
  }
 }
}

//*x = or replace that enum with a vector3 in the JoystickTexture class or whatever you need to define the direction

Though i hope i understood what you wanted :stuck_out_tongue: