我无法改变统一的动画状态

时间:2015-03-03 14:29:34

标签: unity3d animation raycasting

public class TranslatreDora : MonoBehaviour {

    public Vector3 WalkSpeed;
    public  Animator walkDora_;
    public float RunSpeedDora=1.6f;
    private Rigidbody DoraRigidBody;
    public Vector3 JumpVector;
    private bool Jumping_;
    public Transform DoraFoot_;
    public Vector3 DoraFootRay_;

    void Start () 
    {
        walkDora_.GetComponent<Animator>();
        walkDora_.SetFloat("DoraSpeed", 1);
        DoraRigidBody = GetComponent<Rigidbody>();
    }
        if (Input.GetKeyDown(KeyCode.J) || (Input.GetKey(KeyCode.W) && Input.GetKeyDown(KeyCode.J)))
        {
            Jumping_ = true;
            JumpVector = new Vector3(0, 300, 0);     
            walkDora_.SetBool("Jumping", true);
            walkDora_.SetFloat("JumpFloat", 1);
            Debug.Log("Jump 1");

            DoraRigidBody.AddForce(JumpVector);
            Debug.Log("Jump 1 ing");
            RayCastTest();
        }

        Debug.Log("Finished");
    }
    void RayCastTest()
    {
        Debug.Log("Entered");
        //RayCasting
        Vector3 DoraRayTest = new Vector3(DoraFoot_.position.x, DoraFoot_.position.y, DoraFoot_.position.z);
        Ray RayDoraDown = new Ray(DoraRayTest, Vector3.down);
        Debug.DrawRay(DoraRayTest, Vector3.down, Color.green);
        Debug.Log("Entered 2");
        RaycastHit RHit;
        Debug.Log("Entered 3");

        ***//HERE This if-statement does not even get executed***
        if (Physics.Raycast(DoraRayTest, Vector3.down, 1f))
        {
            Debug.Log("Not still False");
            walkDora_.SetBool("Jumping", false);
            Debug.Log("False");
        }
        Debug.Log("Entered Exit");
    }
}

如果声明甚至不执行,那么我的动画就会卡住。 我希望光线投射只扫描光线,如果我点击跳跃,然后当角色接近地面时应该执行If语句。

0 个答案:

没有答案