
1:背景改黑,大小改8.5

2:長寬比改為5:4

3:Ctrl shift +C 調(diào)出控制臺、

4:保存Game到 新建Scenes文件夾中

5:新建3D 立方體 ,當(dāng)移動參照物

6:建立文件夾,放置對象

7:放置對象 動畫 動畫控制文件夾

8:Player裝腳本:
public class Player : MonoBehaviour
{
? ? public float moveSpeed = 3;
? ? // Start is called before the first frame update
? ? void Start()
? ? {
? ? }
? ? // Update is called once per frame
? ? void Update()
? ? {
? ? ? ? float h = Input.GetAxisRaw("Horizontal");
? ? ? ? transform.Translate(Vector3.right * h * moveSpeed * Time.deltaTime,Space.World);
? ? ? ? float v = Input.GetAxisRaw("Vertical");
? ? ? ? transform.Translate(Vector3.up * v * moveSpeed * Time.deltaTime, Space.World);
? ? }
}

9:TankSprite中放入四個方向圖
public class Player : MonoBehaviour
{
? ? public float moveSpeed = 3;
? ? // Start is called before the first frame update
? ? private SpriteRenderer sr;
? ? public Sprite[] tankSprite;//上 右 下 左
? ? private void Awake()
? ? {
? ? ? ? sr = GetComponent<SpriteRenderer>();
? ? }
? ? void Start()
? ? {
? ? }
? ? // Update is called once per frame
? ? void Update()
? ? {
? ? ? ? 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];
? ? ? ? }
? ? ? ? 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];
? ? ? ? }
? ? }
}

10:圖層順序,添加子彈,設(shè)置坦克移動方式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
? ? //屬性值
? ? public float moveSpeed = 3;
? ? //引用
? ? private SpriteRenderer sr;
? ? public Sprite[] tankSprite;//上 右 下 左
? ? private void Awake()
? ? {
? ? ? ? sr = GetComponent<SpriteRenderer>();
? ? }
? ? void Start()
? ? {
? ? }
? ? void Update()
? ? {
? ? }
? ? private void FixedUpdate()
? ? {
? ? ? ? Move();
? ? }
? ? //坦克移動方法
? ? private void Move()
? ? {
? ? ? ? float v = Input.GetAxisRaw("Vertical");
? ? ? ? transform.Translate(Vector3.up * v * moveSpeed * Time.fixedDeltaTime, 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.fixedDeltaTime, Space.World);
? ? ? ? if (h < 0)
? ? ? ? {
? ? ? ? ? ? sr.sprite = tankSprite[3];
? ? ? ? }
? ? ? ? else if (h > 0)
? ? ? ? {
? ? ? ? ? ? sr.sprite = tankSprite[1];
? ? ? ? }
? ? }
}