- Home /
transferring Sprite Mesh Animation frame value to another scene
Hi, I am trying to transfer sprite mesh animation frame to another scene. The sprite mesh animation consist of character clothes , is it actually possible to transfer this value to another scene? I have try creating static variable. But that doesn't help. My other option is to use one scene instead of multiple scene. However I am a little scare if it will eat up player computer resource.
I am using Anima 2D. here's my code. maybe there's something wrong with it.`enter code here
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Anima2D;
public class Wardrobe : MonoBehaviour
{
public static int Clothing = 0;
public Animator animator;
public SpriteMeshAnimation Body;
public SpriteMeshAnimation HandRt;
public SpriteMeshAnimation HandLt;
public SpriteMeshAnimation LegLt;
public SpriteMeshAnimation LegRt;
public void WardrobeShow()
{
animator.SetBool("Wardrobe", true);
}
public void WardrobeHide()
{
animator.SetBool("Wardrobe", false);
}
public void ChangeClothes(int Clothing)
{
print("the clothes no is now" + Clothing + "this is function");
Body.frame = Clothing;
HandRt.frame = Clothing;
HandLt.frame = Clothing;
LegLt.frame = Clothing;
LegRt.frame = Clothing;
}
void Update()
{
if (Clothing >= 1)
{
print("the clothes no is now" + Clothing + "this is update");
Body.frame = Clothing;
HandRt.frame = Clothing;
HandLt.frame = Clothing;
LegLt.frame = Clothing;
LegRt.frame = Clothing;
}
}
}
Answer by mansoor090 · Jan 18, 2019 at 11:48 AM
have you ever used singleton method ? private static Sample instance;
private Sample ()
{
}
public static Sample Instance {
get {
if (instance == null) {
instance = new Sample ();
}
return instance;
}
}
public SpriteMeshAnimation Body;
public SpriteMeshAnimation HandRt;
public SpriteMeshAnimation HandLt;
public SpriteMeshAnimation LegLt;
public SpriteMeshAnimation LegRt;
And now you can use it everywhere no matter what scene you are.
Somehow i figure that the update is not being called, so i change few thing in script. I am completely new to c# program$$anonymous$$g and really want to learn everything I can. I do notice that the Clothing value will always be 0, even if I declare in runtime to 1. Hence, I declare it in new static variable. Hope it doesn't cause problem in the future. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Anima2D;
public class Wardrobe : $$anonymous$$onoBehaviour
{
public static int Clothing = 0;
public Animator animator;
public Sprite$$anonymous$$eshAnimation Body;
public Sprite$$anonymous$$eshAnimation HandRt;
public Sprite$$anonymous$$eshAnimation HandLt;
public Sprite$$anonymous$$eshAnimation LegLt;
public Sprite$$anonymous$$eshAnimation LegRt;
private static int ClothesNo = 0;
public void WardrobeShow()
{
animator.SetBool("Wardrobe", true);
}
public void WardrobeHide()
{
animator.SetBool("Wardrobe", false);
}
public void ChangeClothes(int Clothing)
{
print("Clothing No is now" + " " + Clothing);
ClothesNo = Clothing;
}
void Update()
{
if (ClothesNo >= 1)
{
print("the clothes no is now" + Clothing + "this is update");
Body.frame = ClothesNo;
HandRt.frame = ClothesNo;
HandLt.frame = ClothesNo;
LegLt.frame = ClothesNo;
LegRt.frame = ClothesNo;
}
}
}