Unity:添加对撞机会改变GameObject动作

时间:2017-11-27 19:15:37

标签: c# unity3d

我正在尝试实例化一个新的子弹预制件,并以恒定速度从原点移动它。这很好用:

void OnCollisionEnter(){
        Debug.Log ("collide");
        GameObject expl = Instantiate(explosion, transform.position, Quaternion.identity) as GameObject;
        Destroy(gameObject);
        Destroy(expl, 3);
    }

但是,我也想让它触发爆炸效果。我取消注释添加SphereCollider的行。另一个GameObject(带有对撞机)有这个代码:

 // File and chooser
    private File file;
    private FileInputStream fis;
    private JFileChooser chooser;

    // Date properties
    private SimpleDateFormat dateFormat;

    // Apache POI properties
    private HSSFWorkbook workbook;
    private HSSFSheet sheet;
    private HSSFRow row;

    // Index
    private int index;

    // Properties
    private Dao<Stock> daoStock = null;

    private List<Stock> stockList;

    public void exportStockToXls() // Export XLS files
        {
            workbook = new HSSFWorkbook();
            sheet = workbook.createSheet("Estoque");

            // File name
            file = new File("Estoque.xls");

            // File chooser
            chooser = new JFileChooser();

            // Chooser properties
            chooser.setDialogTitle("Exportar para XLS");
            chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            chooser.setFileFilter(null);

            chooser.setFileFilter(new FileFilter()
            {
                @Override
                public String getDescription()
                {
                    return "XLS File"; // Chooser description
                }

                @Override
                public boolean accept(File f)
                {
                    return f.getName().toLowerCase().endsWith("xls"); // File name
                }
            });

            int action = chooser.showSaveDialog(null); // Store user choice

            if (action == JFileChooser.APPROVE_OPTION) // Checks the user's choice
            {
                file = chooser.getSelectedFile();
                String fileString = file.toString();

                if (fileString.toLowerCase().endsWith("xls") == false)
                {
                    fileString += ".xls";
                    file = new File(fileString);
                }

                // Search for data to export
                try
                {
                    daoStock = new SerializerStock();
                    stockList = daoStock.searchAll();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }

                index = 0;

                // Exporting
                for (Stock stock : stockList)
                {
                    HSSFRow row = sheet.createRow(index);
                    row.createCell(0).setCellValue(stock.getCode());
                    row.createCell(1).setCellValue(stock.getProductName());
                    row.createCell(2).setCellValue(stock.getSalePrice());

                    index++;
                }

                try
                {
                    workbook.write(file); // Write file
                    workbook.close(); // Closing flow after export
                    JOptionPane.showMessageDialog(null, "Arquivo exportado com sucesso!", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                }
                catch (IOException e)
                {
                    JOptionPane.showMessageDialog(null, "Erro ao exportar arquivo!", "Erro", JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace();
                }
            }
        }

一旦我取消注释添加SphereCollider的行,就会触发爆炸(根据需要)。然而,子弹似乎随机移动(它不再平稳地从相机移动)。关于添加对撞机的事情会使平滑变换变得混乱。

我做错了什么?

0 个答案:

没有答案