using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float moveSpeed = 3;//属性值
private SpriteRenderer sr;//引用
private void Awake()
{
sr = GetComponent
}
public Sprite[] tankSprite;//上,右,下,左。
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
Move();
}//移动方法
private void Move()
{
float v = Input.GetAxisRaw("Vertical");
transform.Translate(Vector3.up * v * moveSpeed * Time.deltaTime, Space.World);
if (v < 0)
{
sr.sprite = tankSprite[2];
}
else if (v > 0)
{
sr.sprite = tankSprite[0];
}
if (v != 0)
{
return;
}
float h = Input.GetAxisRaw("Horizontal");
transform.Translate(Vector3.right * h * moveSpeed * Time.deltaTime, Space.World);
if (h < 0)
{
sr.sprite = tankSprite[3];
}
else if (h > 0)
{
sr.sprite = tankSprite[1];
}
}
}