Unity3D字符故障

时间:2016-11-17 17:23:26

标签: c# animation unity3d

我的角色和动画师出现故障时出现问题:https://www.dropbox.com/s/pigrfr98p7oscx3/IMG_1876.MOV?dl=0

我有一个C#脚本,可以在pawn piece和Humanoid图之间切换。我有另一个脚本处理点击移动动作,我将包括:

public class MC : MonoBehaviour {

    private float speed = 10;                   //Speed of Player
    private Vector3 targetPosition;             //Location of MouseClick; where to move to
    private bool isMoving;                      //Check to see if moving
    Animator anim;                              //Animates Humanoid Piece

    void Start ()
    {
        targetPosition = transform.position;        //Current location
        anim = GetComponent<Animator>();            //Gets Animator Controller attached to Piece
        isMoving = false;                   
    }

    void Update ()
    {
        //If the mouse is clicked
        if (Input.GetMouseButton (0)) {
            //If piece is selected; not moved yet 
            anim.SetBool ("isSelected", true);
            SetTargetPosition ();
            //if we are still moving, then move the player
            if (isMoving) {
                MovePlayer ();
            }
        }
    }
    /// Sets the target position we will travel too.
    void SetTargetPosition()
    {
        Plane plane = new Plane(Vector3.up, transform.position);
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        float point = 0f;

        if (plane.Raycast (ray, out point)) {
            targetPosition = ray.GetPoint (point);
        }

        //The humanoid piece is being moved
        isMoving = true;
    }
    /// <summary>
    /// Moves the player in the right direction and also rotates them to look at the target position.
    /// When the player gets to the target position, stop them from moving.
    /// </summary>
    void MovePlayer()
    {
        transform.LookAt(targetPosition);

        transform.position = Vector3.MoveTowards( transform.position, targetPosition, speed * Time.deltaTime);
        anim.SetBool ("isWalking", true);
        //if we are at the target position, then stop moving
        if(transform.position == targetPosition)
            isMoving = false;
    }

**编辑:添加动画树的图片 Adding a picture of the Animation Tree

0 个答案:

没有答案