1.前言:《坦克大战》是由日本南梦宫Namco游戏公司开发的一款平面射击游戏,于1985年发售。游戏以坦克战斗及保卫基地为主题,属于策略型联机类。同时也是FC平台上少有的内建关卡编辑器的几个游戏之一,玩家可自己创建独特的关卡,并通过获取一些道具使坦克和基地得到强化。而且本文章主要是脚本描述
使用的版本是unity2021版以及vs2019
资源包链接:https://pan.baidu.com/s/1x5Hd6nCb2iXz0aBagbnz2g
提取码:2536
2.效果图
3.脚本设计
出生效果:
public class Born : MonoBehaviour
{
[Header("坦克生成特效脚本:补充代码,实现要求")]
public GameObject playerPrefab;
public GameObject enemyPrefab;
public bool createPlayer;
void Start()
{
Invoke("BornTank", 1f);
Destroy(gameObject, 1);
}
private void BornTank()
{
if (createPlayer)
{
Instantiate(playerPrefab, transform.position, Quaternion.identity);
}
else
{
Instantiate(enemyPrefab, transform.position, Quaternion.identity);
}
}
}
子弹移动:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullect : MonoBehaviour
{
public float moveSpeed = 10f;
public bool IsPlayerBullect = true;
void Update()
{
transform.Translate(transform.up * moveSpeed * Time.deltaTime, Space.World);
}
private void OnTriggerEnter2D(Collider2D collision)
{
switch (collision.tag)
{
case "Tank":
if (!IsPlayerBullect)
{
collision.SendMessage("Die");
Destroy(gameObject);
}
break;
case "Heart":
collision.SendMessage("Die");
Destroy(gameObject);
break;
case "Enemy":
if (IsPlayerBullect)
{
collision.SendMessage("Die");
Destroy(gameObject);
}
break;
case "Wall":
Destroy(collision.gameObject);
Destroy(gameObject);
break;
case "Barriar":
Destroy(gameObject);
break;
case "Border":
Destroy(gameObject);
break;
default:
break;