小编Ang*_*nge的帖子

计算保存在文本文件中的2个纬度和经度之间的距离?

我环顾四周,仍然找不到任何可以帮助我的东西!我写了一个程序来计算两个城市之间使用纬度和经度的距离,城市细节保存在一个文件中,然后加载到我的程序中进入BST!到目前为止一切正常,除非我运行代码,假设计算距离我得到每个城市相同的答案!我不太确定为什么我会为每个城市获得相同的答案!请帮我指出正确的方向?

这是计算距离的代码

#include <cmath> 
#define pi 3.14159265358979323846

string userResponse;
float globalLat1, globalLon1, globalLat2, globalLon2;

for(int j= 0; j < 2; j++){
        string whatever;
        if (j==0){
          bool hasbeenfound = false;
           do{
                //ask the user to enter their first city of their choice
                 whatever = "first ";
                  cout << "Enter your " + whatever + "City" << endl;
                  cout << "-------------------" << endl;
                  cin >> userResponse;
                  cout << endl;
                  if (Cities->search(userResponse)) //check if the entered city already exist
                  {
                  hasbeenfound = true; …
Run Code Online (Sandbox Code Playgroud)

c c++

7
推荐指数
1
解决办法
2万
查看次数

如何以编程方式随机生成GameObjects?

我想帮助解决以下问题.我正在做一个简单的游戏,你有一个角色跑,他必须跳过来自他的障碍.

而且我目前在创建GameObjects并在运行时在游戏场景中随机生成它们时遇到困难.

我写了一堂课来帮助实现这个目标:

using UnityEngine;
using System.Collections;

public class randomObstacles : MonoBehaviour {

    public GameObject myCube;
    public Vector3 spawnLocation = new Vector3(0,2,0);

    // Use this for initialization
    void Start () {
        GameObject SpawnLocation = (GameObject)Instantiate(myCube, spawnLocation, Quaternion.identity);
    }

    // Update is called once per frame
    void Update () {

    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码是我写的,只是一个接一个地创建对象.但是当我运行游戏时,它会出现空白-_-!

任何人都可以告诉我哪里出错了,从它的外观我的代码似乎没有做我希望实现的目标:(

我已经将上面的脚本附加到一个空的GameObject中,正如我在Unity社区论坛的教程中看到的那样,但这也没有帮助.(我环顾四周,似乎没有人遇到过这样的问题 - 我可能错了)

c# unity-game-engine

1
推荐指数
2
解决办法
2万
查看次数

标签 统计

c ×1

c# ×1

c++ ×1

unity-game-engine ×1