- Home /
reimporting at runtime?
I know how to reimport an asset from the editor if I accidentally screw it up(right click and select "reimport"), but I want to do from a script, because my script involves screwing up an asset. Is there any way to do this in Unity free, in c#?
Comment
Can we see the script that is making the changes to the asset?
Sure:
using UnityEngine;
using System.Collections;
public class CoolDown : $$anonymous$$onoBehaviour
{
public float coolDown;
public float cooled;
public Color[,] originalTex = new Color[64, 64];
void Start ()
{
Texture2D myTexture = (gameObject.GetComponent ("GUITexture") as GUITexture).texture as Texture2D;
myTexture = Resources.Load (myTexture.ToString ()) as Texture2D;
for (int y=0; y <=63; y++) {
for (int x=0; x<=63; x++) {
originalTex [x, y] = myTexture.GetPixel (x, y);
}
}
}
// Update is called once per frame
void Update ()
{
cooled += Time.deltaTime;
cooled = $$anonymous$$athf.Clamp (cooled, 0, coolDown);
Texture2D myTexture = (gameObject.GetComponent ("GUITexture") as GUITexture).texture as Texture2D;
for (int y=0; y <=63; y++) {
for (int x=0; x<=63; x++) {
myTexture.SetPixel (x, y, originalTex [x, y]);
}
}
if (!Cooled ()) {
int rowsToDo = (64 - $$anonymous$$athf.FloorToInt (64 * (cooled / coolDown))) - 1;
Debug.Log (rowsToDo);
if (rowsToDo != 0) {
for (int y=0; y <=rowsToDo; y++) {
for (int x=0; x<=63; x++) {
Color newPix = myTexture.GetPixel (x, y);
newPix.r = 10;
newPix.g = 10;
newPix.b = 10;
myTexture.SetPixel (x, y, newPix);
}
}
}
myTexture.Apply ();
}
}
public bool Cooled ()
{
if (cooled == coolDown) {
return true;
} else {
return false;
}
}
public void UseAbility ()
{
if (Cooled ()) {
Debug.Log (gameObject.name + " ability!");
cooled = 0;
} else {
Debug.Log (gameObject.name + " ability cound not be used");
}
}
}
Your answer
Follow this Question
Related Questions
Generating script runtime 1 Answer
Multiple Cars not working 1 Answer
Cannot assign assets to variables via inspector: NullReferenceException 3 Answers
Distribute terrain in zones 3 Answers
Submesh creation from script 3 Answers