public class Spritcontroller : MonoBehaviour\n{\n public static int spiritvalue = 25; // 将spiritvalue声明为public static\n private Animator animator;\n // Start is called before the first frame update\n void Start()\n {\n animator = GetComponent();\n }\n // Update is called once per frame\n void Update()\n {\n if (spiritvalue == 0)\n {\n animator.SetFloat("Blend", 0);\n }\n if (spiritvalue == 5)\n {\n animator.SetFloat("Blend", 0.1f);\n }\n // 其他条件判断省略...\n }\n}\n\npublic class OtherClass : MonoBehaviour\n{\n void Start()\n {\n int value = Spritcontroller.spiritvalue; // 使用类名访问spiritvalue\n // 其他逻辑...\n }\n}

Unity C#:在其他类中访问Spiritcontroller的spiritvalue变量

原文地址: https://www.cveoy.top/t/topic/p5aK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录