预订Ammo Formula

时间:2015-06-06 23:33:22

标签: unity3d frame-rate

这是我的问题。我正在使用Counter-Strike / TF2esque弹药系统制作FPS。我的问题是,当我从一个1/1弹药状态(如在一个腔室,一个储备中)重新加载时,我当前的公式给出了一些奇怪的,错误的结果。我的系统将从空气中产生额外的一轮。这是我目前的公式:

myReserve = myReserve - (magSize - boolet);
        boolet = magSize;
        if (myReserve < 0){
            myReserve = 0;
}

有没有人有这方面的程序化解决方案(甚至更好,纯数学)? 代码是UnityScript,如果相关的话。 谢谢!

1 个答案:

答案 0 :(得分:0)

您的代码使用if语句显式创建弹药,因为您将负myReserve值转换为零。让我重构你的代码,这正是你现在编写的代码:

# main.py
import sys
import sqlite3
import ViewWindow
from DataWindow import DataWindow
from PyQt5.QtCore import QObject # I tried adding this line, but nothing changed...
from PyQt5.QtWidgets import (QApplication,
                         QWidget,
                         QGridLayout,
                         QHBoxLayout,
                         QLabel,
                         QLineEdit,
                         QPushButton,
                         QTextEdit,
                         QVBoxLayout
                         )


class MainWindow(QWidget):
    # Some cool stuff


# ViewWindow.py
import sys
import sqlite3
from PyQt5.QtCore import QObject # same thing than above, adding this line doesn't change the output.
from PyQt5.QtWidgets import (QApplication,
                         QWidget,
                         QGridLayout,
                         QLabel,
                         QPushButton,
                         QVBoxLayout
                         )


class ViewWindow(QWidget):

如果您需要询问myReserve&lt; 0,你应该已经知道你做错了什么。 transferedAmmo永远不应该大于myReserve:

var transferedAmmo = magSize - boolet;
myReserve -= transferedAmmo;
boolet += transferedAmmo;
if (myReserve < 0)
    myReserve = 0;