纹理加载使用字符串到 int 替换问题
本文关键字:int 替换 问题 字符串 加载 纹理 | 更新日期: 2023-09-27 18:35:35
根据我的调试日志,问题是我的整数计数没有问题,但是整数到字符串的转换继续应用于原始值,而不是运行时更新的计数器。(这里有一些未使用的私有用于测试)并且帧值都很好。我的调试日志的屏幕截图:http://c2n.me/39GlfuI - 如您所见,计数器增加,但"帧"没有。
希望这是不言自明的
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()
{
}
}
这是因为首先你的下一帧是"frame_000"
所以 replace 方法将000
替换为21
,如您所见,但之后你的 nextFrame 变量是"frame_21"
所以你的字符串中没有"000"
所以你的替换方法不会做任何事情,所以nextFrame
将保持在frame_21
Nextframe = Nextframe.Replace ("000", framestring);
在第一次替换后不会执行任何操作,因为它的字符串不会连接000
啊,非常感谢,所以我对替换功能的理解不正确,我认为它会在每次更新时重置为frame_000。非常感谢大家。是的,我会尝试提高效率。另外,对不起,我还不能投票;没有足够的"代表"。