如何通过简单的按钮“使用”允许用户启用更改动画控制器&精灵渲染器?
在为角色购买新皮肤后,他点击“使用”,当他进入游戏时,皮肤就会启用。
我已经有5个准备好的动画师控制器(Bee1,Bee2,Bee3,Bee4)和Bee as defaut。
精灵渲染已准备就绪(Bee1_0,Bee2_0,Bee3_0,Bee4_0)和Bee_0为默认值。
请尽可能使用C#(使用Unity3D)
如有必要,在脚本播放器下方
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
public class Bee : MonoBehaviour {
public float moveSpeed;
public Transform bee;
private Animator animator;
public bool isGrounded = true;
public float force;
public float jumpTime = 0.1f;
public float jumpDelay = 0.1f;
public bool jumped = false;
public Transform ground;
// Use this for initialization
void Start ()
{
animator = bee.GetComponent<Animator> ();
}
void Update ()
{
Move ();
}
void Move ()
{
isGrounded = Physics2D.Linecast (this.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Floor"));
animator.SetFloat ("runB", Mathf.Abs (CrossPlatformInputManager.GetAxis ("Horizontal")));
if (CrossPlatformInputManager.GetAxisRaw ("Horizontal") > 0) {
transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
if (CrossPlatformInputManager.GetAxisRaw ("Horizontal") < 0) {
transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 180);
}
if (CrossPlatformInputManager.GetButtonDown ("Vertical") && isGrounded && !jumped) {
// rigidbody2D.AddForce (transform.up * force);
GetComponent<Rigidbody2D> ().AddForce (transform.up * force);
jumpTime = jumpDelay;
animator.SetTrigger ("jumpB");
jumped = true;
}
jumpTime -= Time.deltaTime;
if (jumpTime <= 0 && isGrounded && jumped) {
animator.SetTrigger ("groundB");
jumped = false;
}
}
}
答案 0 :(得分:0)
您要找的是RuntimeAnimatorController。没有测试代码,但用法是
animator = bee.GetComponent< Animator >();
animator.runtimeAnimatorController = Resources.Load("Bee1") as RuntimeAnimatorController;
//or:
RuntimeAnimatorController animator = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Bee1", typeof(RuntimeAnimatorController)));
bee.GetComponent< Animator >().runtimeAnimatorController = animator;