我的角色正在制作动画,但仍然不动

时间:2019-02-03 02:02:13

标签: c# unity3d

我刚开始学习的团结和我也正在为学校项目的比赛。我的2D游戏角色可以做步行动画,当我按下“a”和“d”键和精灵翻转,但它停留在相同的位置。下面是我的PlayerController脚本

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

public class PlayerController : MonoBehaviour
{

    private float speed = 3f;
    private Animator anim;
    private SpriteRenderer sr;

    // Start is called before the first frame update
    void Awake()
    {
        anim = GetComponent<Animator>();
        sr = GetComponent<SpriteRenderer>();
    }

    // Update is called once per frame
    void Update()
    {
        Move();
    }

    void Move()
    {
        float h = Input.GetAxisRaw("Horizontal");
        Vector3 temp = transform.position;

        if (h > 0)
        {
            temp.x += speed * Time.deltaTime;
            sr.flipX = true;
            anim.SetBool("Walk", true);

        }
        else if (h < 0)
        {
            temp.x -= speed * Time.deltaTime;
            sr.flipX = false;
            anim.SetBool("Walk", true);
        }
        else if (h == 0)
        {
            anim.SetBool("Walk", false);
        }
    }



}

1 个答案:

答案 0 :(得分:0)

您要将'temp'设置为等于transform.position,但这并不意味着transform.position等于'temp'。在这里,下面的脚本应该给您您想要的

 {
   "size":0,       
   "query":{
      "bool":{
         "must":[
            { "match":{ "base":"FIAT" } },                
            { "match":{ "Type":"SELL" } }
         ]
      }
   },
   "aggs":{
      "sources":{
         "terms":{ "field":"Id" },
         "aggs":{
            "latest":{              
               "top_hits":{
                  "size":1,                      
                  "_source":{
                     "includes":[
                        "Id",
                        "orderDate",
                        "status"
                     ]
                  },
                  "sort":{ "orderDate":"desc" }
               }
            }
         }
      }
   }
}