0

The issue according to my debug log is that my ints counts with no problem however the int to string conversion continues to apply to the original value not the updated counter on runtime. (there are some unused private's here for testing) & the frame values are all good. a screen shot of my debug log: http://c2n.me/39GlfuI - as you can see the counter increases but 'frame' doesn't.

Hopefully this is self explanatory

using UnityEngine;
using System.Collections;
public class imagecycle : MonoBehaviour
{
    public string Startingframe;
    private string Nextframe;
    private int framecomp = 0;
    private int frameint;
    private int framestep = 1;
    private int maxframe = 119; 
    private string framestring;

    // Use this for initialization
    void Start ()
    {
        Nextframe = ("frame_000");
        frameint = 20;   // currently adding one to this and resetting on update
    }

    // Update is called once per frame
    void Update ()
    {
        frameint += framestep;

        //Converts framestring to int of frameint -updating frame  
        framestring = frameint.ToString();

        Debug.Log (frameint);

        // replaces loaded texture recourse with frame string:
        Nextframe = Nextframe.Replace ("000", framestring);
        // Loads texture into Currentframe:
        Texture Currentframe = Resources.Load (Nextframe) as Texture;
        // Applies texture:
        renderer.material.mainTexture = Currentframe;
        Debug.Log (Currentframe);

        if (frameint > 119) 
        {
            frameint = 1;
        }
    }   

    void LateUpdate()
    {
    }
}
Alex Myers
  • 6,196
  • 7
  • 23
  • 39
  • Please see https://stackoverflow.com/help/mcve and https://stackoverflow.com/help/how-to-ask. Please do not include links to external resources in your post. If you want to reference images like screenshots, insert them into your post directly. – Peter Duniho Dec 30 '14 at 07:39
  • You do not plan on loading (from disk!) a texture every frame, right? If you do, please read a tutorial on how to create texture animations in Unity. Your approach will cause performance issues. Depending on the size of the texture it may not load within 0.016 seconds, ie dropping fos below 60. And ultimately a 60 fps texture animation is super-wasteful. – CodeSmile Dec 30 '14 at 09:00
  • rgr that with the links. – Jamie Nicholl-Shelley Dec 30 '14 at 13:34
  • And yeah I choose this method as the textures are super low res, I considered combining them all into one texture then changing the rect co-ords but I didn't see a performance difference in my tests at least. IF there's an alternative to this please give me a shout :) – Jamie Nicholl-Shelley Dec 30 '14 at 13:37

2 Answers2

0

that is because in first your next frame is "frame_000" so the replace method will replace 000 with 21 as you can see but after that your nextFrame variable is "frame_21" so there is no "000" in your string so your replace method wont do anything so nextFrame will stay at frame_21

Nextframe = Nextframe.Replace ("000", framestring); wont do anything after the first replace because its string doesnt conatins 000

Milad Qasemi
  • 3,011
  • 3
  • 13
  • 17
  • probably easier to just build the nextframe each time rather than build it from the current one... `NextFrame = "frame_" + frameint.ToString("D3")` – Lefty Dec 30 '14 at 08:36
  • ah yes I would normally if I didn't have 119 textures :) - was considering this with an array call – Jamie Nicholl-Shelley Dec 30 '14 at 13:38
0

Ah many thanks, so it was my understanding of the replace function that was incorrect, I assumed it would reset to frame_000 on on each update. Many thanks guys. And yeah i'll try making it more efficient. Also ,sorry I can't vote up yet; not enough 'rep'.