Unity3d Unity 2d动画控制器,空闲动画问题
如何将空闲动画添加到此代码中?我试图在给定关键点的if中使用GetButtonUp(关键点释放时应播放动画),然后在括号中使用Player.GetComponent().Play(“goidle”);每个if都是这样,但我似乎不工作Unity3d Unity 2d动画控制器,空闲动画问题,unity3d,animation,Unity3d,Animation,如何将空闲动画添加到此代码中?我试图在给定关键点的if中使用GetButtonUp(关键点释放时应播放动画),然后在括号中使用Player.GetComponent().Play(“goidle”);每个if都是这样,但我似乎不工作 using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimationController : MonoBehaviour {
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationController : MonoBehaviour
{
public GameObject Player;
void Update()
{
if (Input.GetButtonDown("Vertical")) //pressing w
{
Player.GetComponent<Animator>().Play("goup");
}
if (Input.GetButtonDown("VerticalDown")) //pressing s
{
Player.GetComponent<Animator>().Play("godown");
}
if (Input.GetButtonDown("Horizontal")) //pressing d
{
Player.GetComponent<Animator>().Play("goright");
}
if (Input.GetButtonDown("HorizontalDown")) //pressing a
{
Player.GetComponent<Animator>().Play("goleft");
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类AnimationController:MonoBehavior
{
公共游戏对象玩家;
无效更新()
{
if(Input.GetButtonDown(“垂直”)//按w
{
Player.GetComponent().Play(“goup”);
}
if(Input.GetButtonDown(“VerticalDown”)//按s
{
Player.GetComponent().Play(“仓库”);
}
if(Input.GetButtonDown(“水平”)//按d
{
Player.GetComponent().Play(“goright”);
}
if(Input.GetButtonDown(“HorizontalDown”)//按
{
Player.GetComponent().Play(“高尔夫”);
}
}
下面是我尝试使用GetButtonUp并开始播放各个方向的空闲动画时的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationController : MonoBehaviour
{
public GameObject Player;
void Update()
{
if (Input.GetButtonDown("Vertical"))
{
Player.GetComponent<Animator>().Play("goup");
}
if (Input.GetButtonUp("Vertical"))
{
Player.GetComponent<Animator>().Play("idleup");
}
if (Input.GetButtonDown("VerticalDown"))
{
Player.GetComponent<Animator>().Play("godown");
if (Input.GetButtonUp("VerticalDown"))
{
Player.GetComponent<Animator>().Play("idledown");
}
}
if (Input.GetButtonDown("Horizontal"))
{
Player.GetComponent<Animator>().Play("goright");
if (Input.GetButtonUp("Horizontal"))
{
Player.GetComponent<Animator>().Play("idleright");
}
}
if (Input.GetButtonDown("HorizontalDown"))
{
Player.GetComponent<Animator>().Play("goleft");
if (Input.GetButtonUp("HorizontalDown"))
{
Player.GetComponent<Animator>().Play("idleleft");
}
}
}
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类AnimationController:MonoBehavior
{
公共游戏对象玩家;
无效更新()
{
if(Input.GetButtonDown(“垂直”))
{
Player.GetComponent().Play(“goup”);
}
if(Input.GetButtonUp(“垂直”))
{
Player.GetComponent().Play(“idleup”);
}
if(Input.GetButtonDown(“垂直向下”))
{
Player.GetComponent().Play(“仓库”);
if(Input.GetButtonUp(“VerticalDown”))
{
Player.GetComponent().Play(“idledown”);
}
}
if(Input.GetButtonDown(“水平”))
{
Player.GetComponent().Play(“goright”);
if(Input.GetButtonUp(“水平”))
{
Player.GetComponent().Play(“idleright”);
}
}
if(Input.GetButtonDown(“HorizontalDown”))
{
Player.GetComponent().Play(“高尔夫”);
if(Input.GetButtonUp(“HorizontalDown”))
{
Player.GetComponent().Play(“idleleleft”);
}
}
}
}
在所有ifs之后,您是否尝试过简单地使用else条件
很像
如果你这么做
如果你这么做
如果你做点别的
else Player.GetComponent().Play(“goidle”)
为了使你的代码更整洁,你可以在动画师开始时添加一个getComponent
public class AnimationController : MonoBehaviour
public GameObject Player;
Animator playerAnimator;
void Start()
{
playerAnimator = Player.GetComponent<Animator>().
}
void Update()
{
if (Input.GetButtonDown("Vertical"))
{
playerAnimator.Play("goup");
}
if (Input.GetButtonDown("VerticalDown"))
{
playerAnimator.Play("godown");
}
if (Input.GetButtonDown("Horizontal"))
{
playerAnimator.Play("goright");
}
if (Input.GetButtonDown("HorizontalDown"))
{
playerAnimator.Play("goleft");
}
else
{
playerAnimator.Play("goidle")
}
}
公共类AnimationController:MonoBehavior
公共游戏对象玩家;
动画师;
void Start()
{
playerAnimator=Player.GetComponent