开发捕鱼小游戏Unity-3D《炮火威力修改》

切换枪下了一个脚本

GameController.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
// 装炮的数组
public GameObject[] gunObjects;
// text
public Text shootCostText;
// 当前使用的是什么等级的子弹
private int costIndex = 0;
// 一次射击消耗的金币,造成的伤害
private int[] shootCosts = {5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000};
// 加威力的按钮
public void OnButtonIncreaseDown(){
// 禁用炮台,判断更改炮台型号
gunObjects [costIndex / 4].SetActive(false);
// 按下按钮增加消耗金币
costIndex++;
// 如果消耗金币超过1000,让他变回消耗5
costIndex = (costIndex > shootCosts.Length - 1) ? 0 : costIndex;
// 启用炮台
gunObjects [costIndex / 4].SetActive(true);
// 修改UI下方的金币消耗
shootCostText.text = "¥" + shootCosts [costIndex];
}
// 减威力的按钮
public void OnButtonDecreaseDown(){
// 禁用炮台,判断更改炮台型号
gunObjects [costIndex / 4].SetActive(false);
// 按下按钮减少消耗金币
costIndex--;
// 如果消耗金币低于5,让他变回消耗1000
costIndex = (costIndex < 0) ? shootCosts.Length - 1 : costIndex;
// 启用炮台
gunObjects [costIndex / 4].SetActive(true);
// 修改UI下方的金币消耗
shootCostText.text = "¥" + shootCosts [costIndex];
}
// 通过鼠标滚轮来修改消耗金币的数量
void ChangeBullietCostByMouse(){
if (Input.GetAxis("Mouse ScrollWheel") < 0){
OnButtonIncreaseDown ();
}
if (Input.GetAxis("Mouse ScrollWheel") > 0){
OnButtonDecreaseDown ();
}
}
void Update(){
// 每帧调用
ChangeBullietCostByMouse ();
}
}

这里写图片描述

发表评论
留言与评论(共有 0 条评论)
   
验证码:

相关文章

推荐文章

'); })();