动画触发器由于脚本而无法启动

时间:2019-07-10 15:20:44

标签: unity3d

我正在制作3D格斗游戏,我有一个空闲空间和一个步行触发器,但是当我玩游戏时,移动角色后,角色将保持相同的动作(“空闲”)。我进行过渡,不起作用,输入参数,也不起作用。这是脚本。我为实际的动画师屏幕制作了一些屏幕截图,让操作无需过渡。我能做什么?

picture animator

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
    private Animator anim;

    public float moveSpeed = 300;
    public GameObject character;
    private Rigidbody characterBody;
    private float ScreenWidth;
    private Rigidbody rb2d;

    public bool isDead = false;
    public Vector2 jumpHeight;
    public int jumpCount = 0;
    internal static object instance;


    // Use this for initialization
    void Start()
    {
        anim = GetComponent<Animator>();
        ScreenWidth = Screen.width;
        characterBody = character.GetComponent<Rigidbody>();
        rb2d = this.GetComponent<Rigidbody>();
        rb2d.freezeRotation = true;
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {  
        if (isDead) { return; }
        if (jumpCount < 3 && (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)))  //makes player jump
        {
            GetComponent<Rigidbody>().AddForce(jumpHeight, ForceMode.Impulse);
            jumpCount++;
        }
        jumpCount = 0;
        int i = 0;
     
        while (i < Input.touchCount)
        {
            if (Input.GetTouch(i).position.x > ScreenWidth / 2)
            {
                RunCharacter(1.0f);
                anim.Play("walk");

            }
            if (Input.GetTouch(i).position.x < ScreenWidth / 2)
            {
                RunCharacter(-1.0f);
            }
        }
    }

    void FixedUpdate()
    {
#if UNITY_EDITOR
        RunCharacter(Input.GetAxis("Horizontal"));
#endif 
    }

    private void RunCharacter(float horizontalInput)
    {
        characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0));
    }
}

0 个答案:

没有答案