Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Texture Swap Animator from WiKi does not execute on play

Discussion in 'Scripting' started by Exnihilon, Apr 27, 2014.

  1. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello to all. I have tried to use the Texture Swap Animator from Wiki, (see here) and it was working ok, both on Unity play, or on testing device.

    Suddently the script stoped exucuting. I have tried it on a new scene, on a new GameObject, still no good at all.

    What is more, whatever script I have tried in Unity3d (free) for texture swapping as animation, that is posted in the forum, I still get no response at all.

    Is this a Unity bug, or something else is happening?

    Has anyone came uppon the same problem, and what might be a woriking solution?

    Need to have a texture animated in my project.

    Thank you all in advance for your answers.

    EDIT1

    I have tried to add a debug.log as Dantus suggested and I get the message at console that ""Update was executed.14.39214
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js".

    I believe that there is nothing wrong with the script as I get the same message at my new project with a testing scene, where the texture animation is visible on Unity's play.

    I have tried to make a prefab, out of the GameObject that the script is working o.k. at my new project testing scene.

    Then I have this prefab inserted to my initial project in order to get it animating. I thought that a prefab, would be a solution to my problem, but unfotunately, I get no visual of the texture animation on GameObject, on play.

    Any clues, what might be the case, here, are very much wellcomed. Otherways, I would have to make the project from scratch and through out of the window a 2 months work!

    EDIT 2

    I have also tried to move the GameObject that has the Texture Swap Animation script attached, from my initial project, that does not animate on Unity play, to my new testing project as a prefab. Guess what, it animates o.k. on Unity play!

    According to these behaviour, I believe there must be a big "BUG" at Unity engine, otherwise why the same prefab, and script plays o.k. in one project and does not plays at the other?

    What might be a working arround to this bug? Any thoughts, someone? Please respond.

    EDIT 3

    Well, here is what I have came up with, after I have tried many things to make the script work again on GameObject texture.

    I have added a script that gives user the option to guit app or stay in, with the fuctions "application.quit" and "application.pause"

    The coding is as following:

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. var count : int = 0;
    5. function Update () {
    6. if (Input.GetKeyDown(KeyCode.Escape)) {
    7.     Time.timeScale = 0;
    8.     count = 1;
    9.             }
    10. }
    11. function OnApplicationPause()
    12. {
    13. Time.timeScale = 0;
    14. count = 1;
    15. }
    16.  
    17. function OnGUI()
    18. {
    19. if(count == 1)
    20.     {
    21.        GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
    22.        GUI.Label(new Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6), "Are you sure you want to exit the game?");
    23.     if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
    24.           {
    25.          Application.Quit();
    26.           }
    27.           if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
    28.           {
    29.           count = 0;
    30.           Time.timeScale = 1;
    31.           }
    32.     }
    33. }
    34.  
    So far, I had not enabled this "exit" script. Upon enable it in Inspector and hit play in Unity, I also got the "Texture Swap Animator" script running o.k. This is happening after I hit "keep playing" as an option on the "exit" script.

    I believe, the "Texture Swap Animator" script is getting somehow in a "pause" state, because a conflict and therefore is activated once the "keep playing" button is clicked in the "exit" script, which is canceling any "pause" state in app.
    Does this outcome, ring a bell to someone, to make the "Texture Swap Animator" work again flawlessly?

    Waiting for your answers.

    EDIT 4

    As @ThermalFusion and @Dante suggested, the "Time.timeScale" variable is a trigger to whether the "TextureSwapAnimator.js" script runs on a GameObject or not. Strange thing is that this script used to run before I have added the coding of "Time.timeScale" in my other js script that I do a call to run the "TextureSwapAnimator.js" script.
    I have mocked around the "1" and "0" switches in the "Time.timeScale" variable, and I have texture animation as functionality, but I have lost the functionality of the "Exit" script!

    Here is the "Exit" script modifications I've made:

    Code (csharp):
    1.  
    2.  
    3. #pragma strict
    4.  
    5. var count : int = 1;                                          // changed from 0 to 1
    6. function Update () {
    7. if (Input.GetKeyDown(KeyCode.Escape)) {
    8.     Time.timeScale = 1;                                  //changed from 0 to 1
    9.     count = 0;                                                 //changed from 1 to 0
    10.             }
    11. }
    12. function OnApplicationPause()
    13. {
    14. Time.timeScale = 0;
    15. count = 0;                                                   //changed from 1 to 0
    16. }
    17.  
    18. function OnGUI()
    19. {
    20. if(count == 0) // changed from 1 to 0
    21.     {
    22.        GUI.Box(new Rect(0,0,Screen.width,Screen.height),"Exit");
    23.        GUI.Label(new  Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6),  "Are you sure you want to exit the game?");
    24.     if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
    25.           {
    26.          Application.Quit();
    27.           }
    28.           if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"Keep Playing"))
    29.           {
    30.           count = 1;                                     //changed from 0 to 1
    31.           Time.timeScale = 1;
    32.           }
    33.     }
    34. }
    35.  
    Now after all these editing, what do you thing is the problem with this coding? A bug in Unity3d, a conflict in scripting or what else?
    Waiting for your thoughts and answers. Thank you all for your time and efford.
     
    Last edited: May 3, 2014
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Likely you are using a material with a shader that doesn't have/use the _MainTexture property.
    Or maybe missing renderer with materials all together. Otherwise the code would work.
     
  3. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hi @ThermalFusion. I am a newbie in Unity, maybe I have done something that changed those properties. How can I make it work out as it should be? Where should I found those _MainTexture in Inspector? Thanks in advance.
     
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Those properties are found in the shaders. What material are you using? Does it work if you use a material using the Diffuse shader?
     
  5. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hi again @ThermalFusion. I am using the base (RGB) shader of Mobile/Diffuse. I have tried almost every diffuse shader, but still can get it to work.
    Why was this script used to work and now it doesn' t? It is very strange, cause I can't get any texture swapping script to work. Any clues?
     
  6. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Post shots of your setup. Need more info
     
  7. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello again @ThermalFusion. I'm posting a screen shot of Unity's Inspector, showing the properties of the GameObject, used with the texture swap script.
    Hope it might be of anyhelp to you, so we can figure out what is wrong and the script does not run as it should. I should remind you, that when I had started the development of my app in Unity, that script worked ok in every scene, and on any GameObject.

    $InspectorScreenShot.jpg

    EDIT 1.
    Strange thing is that on starting a new project the script works o.k., on every GameObject. Furthermore, I've tried to copy the working attributes of the new project GameObject to my previous project settings, but it didn't work out. It is a pity to start my project from scratch to make this script working again as I've been working on this for about 2 months!
    Is there a bug in Unity3d or something else being broken in its installation and it is not working as before?
     
    Last edited: May 1, 2014
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The mesh renderer needs a material. Add a material and it is going to work.

    If you hit play with that setup, you are getting error messages. it would have been useful if you had posted that information.
     
  9. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello @Dantus. Thank you for your reply to my question. Apologies for double posting. Didn't know if it was a scripting issue or a Unity bug. I still haven't figured it out.

    You recomented to add a material to the mesh renderer, for the script to work. Well, I had already a material applied, but I got no functionality of the script. I have reseted the mesh materials to defauld, still got no script to work in my initial project.

    In the new project everything is working o.k. in Unity play. Furthermore, I got this error messages in console "NullReferenceException: Object reference not set to an instance of an object", but this has nothing to do with the Texture Swap Animator script, cause it is a NyARtoolkit bug I suppose.

    I'm posting two screenshots from Unity Inspector. One (named "A") is from my initial project, where the script used to run o.k., and now it does not runs at all. The second (named "B") is from a new project, that the script runs just fine!.

    $A.jpg $B.jpg

    Any clues, what might be the culprit here? I suppose it might be a Unity bug or something, and what can it be as a solution, to avoid starting project from scratch?
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did you try to change the layer to "2D GUI"?
     
  11. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Yes @Dantus. The initial project has a 2D GUI layer. The new project, that it is used to test the script functionality, has only the default layer.
    I have tested the layers and this is not the issue. I have moved the objects between layers, I have created new camera that sees only the gameobject with the script attached, I get zero functionality from the script in my initial project. No matter what I try in my initial project I get no responce from script in Unity play. I repeat, same settings in new project and everything in script its o.k. What could be broken in my initial Unity project?
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Code (csharp):
    1. var frames : Texture2D[];
    2. var framesPerSecond = 10.0;
    3.  
    4. function Update () {
    5.     var index : int = Time.time * framesPerSecond;
    6.     index = index % frames.Length;
    7.     renderer.material.mainTexture = frames[index];
    8.     Debug.Log ("Update was executed. " + Time.realtimeSinceStartup);
    9. }
    Try to add the Debug.Log to the script to see, whether it gets executed.
     
  13. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Are you pausing time? That would also stop the animation.
     
  14. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello @Dantus. I have added the Debug.Log line at script as you suggested. I get the following message at console:

    "Update was executed.14.39214
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:8)"

    What does this means? Is the script executed, or not? If so, why cannot see the texture animating on GameObject?
     
  15. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hi again, @ThermalFusion. No I'm not pausing time. I just hit "play" in Unity, that all.
     
  16. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Do you only see this message once? This message is printed each time when the texture is swapped.
    Again, do you have other error messages in the console? Any error message is relevant!
     
  17. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hi @Dantus, I get this message uncountable times, as it is an update function I supposed, it is o.k. to be reported so, in console.

    I also get the following error, that has nothing in my opinion to do with the Texture Swap script :
    "NullReferenceException: Object reference not set to an instance of an object". This is a error generated from the NyARtoolkit, but the project used to run o.k, both on player and on testing device.
     
  18. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Change the debug line to
    Code (csharp):
    1. Debug.Log ("Update was executed. Index: " + index + "; " + Time.realtimeSinceStartup);
    Like that you will see the index of the currently shown texture.
     
  19. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    @Dantus, I changed the debug line as you suggested, hit "play" and I got the following message in console:

    "Update was executed. Index: 0; 40.81854 (← this number constantly changes)
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:9)"

    How this report interpretes? I believe the "0" means nothing is rendered? or what?
     
  20. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    0 means always the first frame is shown. Please tell me which value you get, when you replace the Debug.Log with this:

    Code (csharp):
    1. Debug.Log (Time.time);
     
  21. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello Dantus. I have replaced the debug.log as you suggested, and this is what i get in console:

    "8.18365 ← This number is constantly changing... and the animation is played in Game window (see my EDIT 3, why, and when this is happening).
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:14)

    So...what is the meaning of this number?
     
  22. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Have a look at the documentation to understand what Time.time is for.

    Could you try that please and let me know which output you are getting:
    Code (csharp):
    1. var frames : Texture2D[];
    2. var framesPerSecond = 10.0;
    3.      
    4. function Update () {
    5.     var index : int = Time.time * framesPerSecond;
    6.     index = index % frames.Length;
    7.     renderer.material.mainTexture = frames[index];
    8.     Debug.Log (Time.time + ", " + framesPerSecond + ", " + frames.Length + ", " + index);
    9. }
     
  23. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    It seems like you are in fact editing timeScale.
    If you debug Time.timeScale you can see if it is 0. If it is 0 then you have changed it somewhere.
    If it is 0 your time won't advance and texture wont animate.
    Either find a timeScale independent solution, or don't pause time.
     
  24. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's my assumption as well.
     
  25. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello again @Dantus. Here is what I get after I altered the texture animate script as you suggested:

    "0, 3, 19, 0
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)"

    Have you read my EDIT 3 in my post? Any clues why and what it is happening in this coding?
     
  26. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello @ThermalFusion. Nice to hearing from you, about this misfunction in my coding. How can I do debuging to Time.timeScale?
    How can I found if it is chanced somewhere? Should I check all my scripts in every GameObject? I'm new to Unity and programming therefore I need some guidance to make things work again. Thanks in advance.
     
  27. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's the line as it gets executed first. Could you show a few more of those? Not the immediate next ones, just skip a few and that, skip some more, ... you get the idea.

    The answer to edit 3 is RTFM :)
    https://docs.unity3d.com/Documentation/ScriptReference/Time-time.html
     
  28. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Well @Dantus, I have taken a look to the RTFM, many times, but remember I'm just a noob in Unity and programming, so I need time to adjust myself to anything that a coding pops out as a bug or something.

    Anyway, here is some lines as it gets executed:

    "5.27503, 3, 29, 15
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)


    29.18182, 3, 29, 0
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)

    47.05382, 3, 19, 8
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)

    59.67509, 3, 29, 5
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)

    69.13562, 3, 19, 17
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)

    83.55321, 3, 19, 3
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)

    97.91667, 3, 29, 3
    UnityEngine.Debug:Log(Object)
    TextureSwapAnimator:Update() (at Assets/Standard Assets/Scripts/General Scripts/TextureSwapAnimator.js:24)"

    Can you tell me what exactly these lines are telling about the problem?

    Hope they are helpful to you or anyone that want to help out, with this issue.
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you don't understand what those numbers are for, you should really consider to take a programming course or learn a least the basics with online tutorials! All the information you need is in the Debug.Log and should be understandable who knows the basics and asks this kind of question in the forum.

    The lines tell me that there are at least two of those scripts being executed. One of them with 19 frames and the other one with 29. It also tells me that the animation is being executed as there are different textures from the frame list that are being shown.
    Did you make sure that you have a different texture for each frame?!
     
  30. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    @Dantus, if I had your experience in Unity or programming in general, I might be in your place answering a noob's questions, like me. Anyway, I still have a lot to learn, therefore I'm posting here, and asking for anyone willing to help.

    What I have asked you, about these lines, was to tell me if you could, about the problem in the coding, considering of course, all the edits I have posted, so far. I understand what the numbers represent in the debug.log, allright.

    There are indeed two different GameObjects, that the "TextureSwapAnimator.js" script is attached to. One is run with a 19 texture frames, the other with a 29 texture frames.

    But I thing we are missing the subject here, which is, why this annoying "TexureSwapAnimator.js" script is fuctioning ok in a new scene, in a new Unity project, started from scratch, and it stopped functioning long before I have added the above mentioned "Exit" script!
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It is not common to modify the original post, I never had a look at it. That was clearly the cause for the confusion. Please don't edit the original post like that!

    Please, post the code again in its current state. If you want any help from me, use proper indentation for the code and explain in a few sentences what you are trying to achieve.
     
  32. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Well @Dantus, it has been certainly a cunfusion. Well I'm reposting the "TextureSwapAnimator.js" as it is now, with the debug.log added:

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4.     var frames : Texture2D[];
    5.     var framesPerSecond = 10.0;
    6.          
    7.     function Update () {
    8.         var index : int = Time.time * framesPerSecond;
    9.         index = index % frames.Length;
    10.         renderer.material.mainTexture = frames[index];
    11.         Debug.Log (Time.time + ", " + framesPerSecond + ", " + frames.Length + ", " + index);
    12.     }
    13.  
    Here is the javascript that I use to control some buttons in my app, including the button to trigger the camera that sees the gameobject with the "TextureSwapAnimator.js" attached to:


    Code (csharp):
    1.  
    2.     #pragma strict
    3.     var native_width :  float = 480;
    4.     var native_height : float = 320;
    5.     var btnTexture1 : Texture;
    6.     var btnTexture2 : Texture;
    7.     var btnTexture3 : Texture;
    8.     var Cam1 : Camera;
    9.     var Cam1On : boolean = false;
    10.     var isExit : boolean = true;
    11.     var count : int = 1;
    12.        
    13.     function Awake ()
    14.     {
    15.      DontDestroyOnLoad (GameObject.FindGameObjectWithTag("animaTexture"));
    16.     }
    17.    
    18.     function Start()
    19.     {
    20.     Cam1.enabled = false;
    21.     }  
    22.    
    23.     //Camera function on/off to see the "animaTexture"
    24.  
    25.     function Update()
    26.     {
    27.     if (!Cam1On)
    28.     {
    29.     Cam1.enabled = false;
    30.     }
    31.     else
    32.     {
    33.        Cam1.enabled = true;
    34.     }
    35.     if (!isExit) // Trigers the "EXIT" button (btnTexture 2)
    36.     {
    37.     Time.timeScale = 1;
    38.     count = 0;
    39.     }
    40.     }
    41.    
    42.     function OnApplicationPause()
    43.     {
    44.     Time.timeScale = 0;
    45.     count = 0;
    46.     }
    47.    
    48.     //start of OnGUI
    49.  
    50.     function OnGUI ()
    51.     {
    52.         //set up scaling
    53.         var rx : float = Screen.width / native_width;
    54.         var ry : float = Screen.height / native_height;
    55.      
    56.         GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
    57.      
    58.         //now create GUI normally, as if in native resolution
    59.         //The GUI.matrix will scale everything automatically.
    60.          
    61.                    
    62.          if (!btnTexture1)
    63.              {
    64.             Debug.LogError("Please assign a texture on the inspector");
    65.             return;
    66.             }
    67.            
    68.             if(GUI.Button(Rect(25, 180, 30, 15), btnTexture1))
    69.             {
    70.             // Load the level named "myScene2".
    71.                 Application.Quit();
    72.                 Application.LoadLevel ("myScene2");
    73.             }
    74.            
    75.             if (!btnTexture2)
    76.                 {
    77.             Debug.LogError("Please assign a texture on the inspector");
    78.             return;
    79.             }
    80.                 if(GUI.Button(Rect(50, 180, 30, 15), btnTexture2))
    81.                 isExit = !isExit;
    82.                 if(isExit)
    83.                 if(count == 0)
    84.                 {
    85.                    GUI.Box(Rect(0,0,Screen.width,Screen.height),"Exit application");
    86.                    GUI.Label(Rect(Screen.width*1/4,Screen.height*2/6,Screen.width*2/4,Screen.height*1/6), "Are you sure you want to exit app ?");
    87.                 if(GUI.Button(Rect(Screen.width/4,Screen.height*3/8,Screen.width/2,Screen.height/8),"Yes"))
    88.                       {
    89.                      Application.Quit();
    90.                       }
    91.                       if(GUI.Button(Rect(Screen.width/4,Screen.height*4/8,Screen.width/2,Screen.height/8),"No thank you, I'll stay"))
    92.                       {
    93.                       count = 1;
    94.                       Time.timeScale = 1;
    95.                   }
    96.                 }
    97.                
    98.            if (!btnTexture3)
    99.                {
    100.             Debug.LogError("Please assign a texture on the inspector");
    101.             return;
    102.             }
    103.             if(GUI.Button(Rect(342, 212, 52, 35), btnTexture3))    
    104.                
    105.                 {
    106.                 Cam1On = !Cam1On;     //This camera renders only the object with the "TextureSwapAnimator.js" script, witch should run on the gameobject texture. It should run only on pressing the button not before.                    }
    107.                                     //It runs now, but the "Exit" button it doesn't behaves as it should, and the application does not pauses.
    108.  
    109.                   //end of OnGUI  
    110. }
    111.  
    Let me repeat the issue here. The initial problem was that "TextureSwapAnimator.js" script, stoped functioning at the scene on play, without having made any alterations to the codding. It played though well, on a new scene, on a new gameobject, in a new project.

    After I mocked arround with the code, I have added the "Exit" button to the codding, and suddently the "TextureSwapAnimator.js" started to behave as it should. This added codding disabled the application "pause" functionality though.

    Hope now, someone can figure out what is wrong with this coding. Thank you @Dantus and all the others, for your time and help.
     
  33. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Why do you change the time scale in the second script?
     
  34. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hello @Dantus. You mean changed from 1 to 0 at line 43 or 93? I have change it, cause if it is set to the initial value 1 the button does not responts on click and the animation script also, does not advance its frames, as it should. As the posted code is now, I have the following functionality:

    - The "TextureSwapAnimator.js" script is working on a gameobject's texture, as it should be. I couldn't figured out, how the Time.timeScale is conflicting with the texture script.

    -The "Exit" button (btnTexture2) is responding to its opsions, but the app is not in "pause" state as it should, as long as the user makes a choise.
     
  35. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I have exactly one problem. I have absolutely no idea what the logic behind your second script is.
     
    Last edited: May 4, 2014
  36. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Hi, @Dantus.
    The second script, just renders some gui.buttons. These gui.buttons trigger other scripts such as a camera on/off that sees only the gameobject with the problematic "TextureSwapAnimator" scripting behaviour. There is also an "Exit" button that quits app, and a "Quit app" button with a 2 choise menu for the user.
    That is all in this coding. What exactly you don't understand in the script's logic? Is not a perfect coding sample, you know, I am a newbie, after all. :wink:
     
  37. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Why are you using OnApplicationPause and why do you use Time.timeScale?
     
  38. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    Why not using OnApplicationPause @Dantus? When the user presses the "Quit app" (btnTexture2) the app should be in pause state, waiting for user's choise form the menu. As for Time.timeScale, why I shouldn't used it in codding?
     
  39. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Sorry, I won't help anymore. Please learn and understand the basics first.
    You can use all the functionality you want in coding. But always make sure it works correctly. There are obviously major issues in your code. In order to get rid of those issues, throw everything out that is not relevant.
     
  40. Exnihilon

    Exnihilon

    Joined:
    Mar 2, 2014
    Posts:
    157
    As you remember @Dantus, that thread started out of a script (TextureSwapAnimator.js) that is functional and anyone, noob or pro, can download and use from the unity.wiki page. It was not my coding, remember?

    Anyway, thanks for your help so far.
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    TextureSwapAnimator is not the problem. The problem is caused by the other script!