RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-349376

cyberfrogg's questions

Martin Hope
cyberfrogg
Asked: 2020-06-15 03:52:11 +0000 UTC

从mysql php数据库输出文本

  • 0

我正在尝试显示数据库中的文本,但由于某种原因显示了一个空变量。

<ul>
            <li>See here:</li>
            <?php
                $link = mysqli_connect("localhost", "root", "root", "test");

                if($link === false){
                    die("ERROR: Could not connect. " . mysqli_connect_error());
                }

                $result = mysqli_query("SELECT 'tex' FROM 'example' WHERE id = '1'");
                echo "<li> $result </li>";

                mysqli_close($link);
            ?>
        </ul>

控制台中没有错误。该页面也会出现。

数据库本身 火车站

php
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-06-12 03:51:44 +0000 UTC

将选定元素推入数组 | jQuery js

  • 1

我选择了 $(".itemimg") 项目(有几个),我想将它们放入一个空列表 var items = []; 怎么做才对。

javascript
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-03-28 20:37:07 +0000 UTC

如何将组件与 Unity 变量等同起来

  • 1
empty.AddComponent<MeshFilter>();
empty.GetComponent<MeshFilter>() = Data_Map.worldObjects[i].meshFilter;

如何将组件等同于变量?这段代码会抛出错误,因为左侧不是变量。

unity3d
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-02-15 05:19:02 +0000 UTC

如何按名称添加组件?

  • 0

有一个对象spawnedObject。我想这样做,以便按其类型添加组件。例如:

string a = "Rigidbody";
spawnedObject.AddComponent<a>();

还是团结超越了它的力量?

c#
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-01-22 21:03:19 +0000 UTC

在几乎整整一代人之后,世界开始滞后很多。Unity 程序地形

  • 0

我有一个程序景观。有瓦片(块),还有一个 Terrain 对象,当接近景观边缘时,由于生成瓦片时有强烈的 FPS 下降,因此通过 Coroutine 生成。如何解决?

左上角 x/y/z 和 fps 坐标。

GIF:https ://imgur.com/a/GCSFpI2

这是放置块的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

class _Chunk
{
    public GameObject theChunk;
    public float creationTime;

    public _Chunk(GameObject t, float ct)
    {
        theChunk = t;
        creationTime = ct;
    }
}

public class WorldProcedural : MonoBehaviour
{
    public GameObject chunk;
    public GameObject player;

    public int ChunkSize = 16;
    public int halfTilesX = 16;
    public int halfTilesZ = 16;

    Vector3 startPos;
    Hashtable chunks = new Hashtable();

    private void FixedUpdate()
    {
        halfTilesX = ESCManager.DrawDistance;
        halfTilesZ = ESCManager.DrawDistance;

        StartCoroutine(UpdateWorld());
    }

    private void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");

        this.gameObject.transform.position = Vector3.zero;
        startPos = Vector3.zero;

        float updateTime = Time.realtimeSinceStartup;

        for (int x = -halfTilesX; x < halfTilesX; x++)
        {
            for (int z = -halfTilesZ; z < halfTilesZ; z++)
            {
                Vector3 pos = new Vector3((x * ChunkSize + startPos.x), 0, (z * ChunkSize + startPos.z));
                GameObject t = (GameObject)Instantiate(this.chunk, pos, Quaternion.identity);
                t.transform.SetParent(transform);

                string tilename = "Chunk_" + ((int)(pos.x)).ToString() +
                    "_" + ((int)(pos.z)).ToString();
                t.name = tilename;
                _Chunk chunk = new _Chunk(t, updateTime);
                chunks.Add(tilename, chunk);
            }
        }
    }

    private IEnumerator UpdateWorld()
    {
        int xMove = (int)(player.transform.position.x - startPos.x);
        int ZMove = (int)(player.transform.position.z - startPos.z);

        if (Mathf.Abs(xMove) >= ChunkSize || Mathf.Abs(ZMove) >= ChunkSize)
        {
            float updateTime = Time.realtimeSinceStartup;

            int playerX = (int)(Mathf.Floor(player.transform.position.x / ChunkSize) * ChunkSize);
            int playerZ = (int)(Mathf.Floor(player.transform.position.z / ChunkSize) * ChunkSize);

            for (int x = -halfTilesX; x < halfTilesX; x++)
            {
                for (int z = -halfTilesZ; z < halfTilesZ; z++)
                {
                    Vector3 pos = new Vector3((x * ChunkSize + playerX), 0, (z * ChunkSize + playerZ));

                    string tilename = "Chunk_" + ((int)(pos.x)).ToString() +
                        "_" + ((int)(pos.z)).ToString();

                    if (!chunks.ContainsKey(tilename))
                    {
                        GameObject t = (GameObject)Instantiate(this.chunk, pos, Quaternion.identity);
                        t.transform.SetParent(transform);
                        t.name = tilename;
                        _Chunk chunk = new _Chunk(t, updateTime);
                        chunks.Add(tilename, chunk);
                    }
                    else
                    {
                        (chunks[tilename] as _Chunk).creationTime = updateTime;
                    }


                }
                yield return new WaitForSeconds(0.5f);
            }

            Hashtable newTerrain = new Hashtable();
            foreach (_Chunk chk in chunks.Values)
            {
                if (chk.creationTime != updateTime)
                {
                    Destroy(chk.theChunk);
                }
                else
                {
                    newTerrain.Add(chk.theChunk.name, chk);
                }
            }

            chunks = newTerrain;
            startPos = player.transform.position;
        }


    }
}
unity3d
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-12-24 05:13:31 +0000 UTC

水平和垂直按钮控制 / Unity 引擎

  • 0

我有两个 UI 按钮。我不想用鼠标控制它们,但我想用箭头或 WASD 来控制它们,它们被突出显示,并且通过按钮,比如说 Enter,事件被激活,就像在常规按钮上一样。(例如,在超级马里奥兄弟的主菜单中)

unity3d
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-12-12 18:32:41 +0000 UTC

物理原因导致的低 FPS | 程序MeshColider

  • 1

如何在 Unity 中优化物理?通过ProfilerUnity,我查看了哪些物理负载最多,而我只有水作为物理对象。我有一个带有随perlinNoise每一帧变化的动态网格的板和一个随这块变化的动态网格对撞机:

Mesh myMesh = this.GetComponent<MeshFilter>().mesh;
DestroyImmediate(this.GetComponent<MeshCollider>());
gameObject.AddComponent<MeshCollider>();
GetComponent<MeshCollider>().sharedMesh = myMesh;

编辑:这是生成水的实际代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WaterNoise : MonoBehaviour
{
    public float power = 3;
    public float scale = 1;
    public float timeScale = 1;

    float offsetX;
    float offsetY;
    MeshFilter mf;

    private void Start()
    {
        mf = GetComponent<MeshFilter>();
        GenNoise();
    }

    private void FixedUpdate()
    {
        GenNoise();
        offsetX += Time.deltaTime * timeScale;
        offsetY += Time.deltaTime * timeScale;
    }

    void GenNoise()
    {
        Vector3 myPos = transform.localPosition;
        Vector3[] vertices = mf.mesh.vertices;

        for(int i = 0; i < vertices.Length; i++)
        {
            vertices[i].y = CalculateHeight(vertices[i].x + myPos.x, vertices[i].z + myPos.z) * power;
        }

        Mesh myMesh = this.GetComponent<MeshFilter>().mesh;
        DestroyImmediate(this.GetComponent<MeshCollider>());
        gameObject.AddComponent<MeshCollider>();
        GetComponent<MeshCollider>().sharedMesh = myMesh;

        mf.mesh.vertices = vertices;
    }

    float CalculateHeight(float x, float y)
    {
        float xCoord = x * scale + offsetX;
        float yCoord = y * scale + offsetY;

        return Mathf.PerlinNoise(xCoord, yCoord);
    }
}

该应用程序是单线程的。

c#
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-10-30 05:01:17 +0000 UTC

c# 中的列表以及如何阅读它们?

  • -1

我有一个相当简单的问题(可能)如何计算具有给定值的列表中的值?例如,我有一个非常大的列表,我想读取包含某个变量数量的行。

print(dots[i]);

其中dots 是一个列表其中i 是行号。

Unity 给出了一个非严重错误:

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

参数名称:索引

从中,我意识到列表中没有这样的行,但我通过调试检查了它 - 值是 64,它在列表中。谢谢你。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class PlanetTerrain : MonoBehaviour
{
    public static int seed;
    public static Color color;
    public static bool deathGas = false;
    public static float amplitude;
    public static float freq;

    public int dotcount = 0;
    public List<Vector2> chunkdots;
    public GameObject tile;
    public int worldSize;

    private void Awake()
    {
        seed = Random.Range(1, 10000);
        amplitude = Random.Range(8, 100);
        freq = Random.Range(83, 100);

        Cursor.lockState = CursorLockMode.Locked;
    }

    private void Start()
    {
        SetPoints();
        StartCoroutine(Generate());
    }
    void SetPoints()
    {
        for (int x = 0; x < worldSize; x++)
        {
            for (int z = 0; z < worldSize; z++)
            {
                dotcount++;
                Debug.Log(dotcount);
                chunkdots.Add(new Vector2(x * 16, z * 16));
            }
        }


    }

    IEnumerator Generate()
    {
        yield return new WaitForSeconds(0.1f);

        for (int i = 0; i < dotcount; i++)
        {
            int ic = 0;
            ic = dotcount;
            Debug.Log("ic = " + ic);
            Instantiate(tile, new Vector3(chunkdots[ic].x, 0, chunkdots[ic].y), Quaternion.identity);

        }
    }
}
c#
  • 2 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-10-26 00:11:28 +0000 UTC

如何生成体素星球?

  • 0

我可以生成正常的体素地形并使用柏林噪声。但是如何首先从立方体生成球体并使用柏林噪声?

unity3d
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-10-22 03:13:41 +0000 UTC

纹理不应用于生成的网格

  • 0

有一个问题,一个脚本,其中一个简单的景观是从三角形生成的。并且草的纹理是通过脚本叠加的。但是在应用纹理之后,网格变成了绿色,好像从纹理中取出了 1 个像素。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(MeshFilter))]
public class ProceduralTerrain : MonoBehaviour
{
Mesh mesh;

Vector3[] vertices;
int[] triangles;

public Renderer rend;
public Texture[] textures;

public int xSize = 100;
public int zSize = 100;

private void Start()
{
    mesh = new Mesh();
    GetComponent<MeshFilter>().mesh = mesh;
    rend = GetComponent<Renderer>();


    rend.material.mainTexture = textures[0];

    CreateShape();
}

private void Update()
{
    UpdateMesh();
}

void CreateShape()
{
    vertices = new Vector3[(xSize + 1) * (zSize + 1)];  //Getting size of grid

    for(int i = 0, z = 0; z <= zSize; z++)
    {
        for (int x = 0; x <= xSize; x++)
        {
            //Setting PerlinNoise and calculating grid
            float y = Mathf.PerlinNoise(x * .01f, z * .01f) * 50f;
            vertices[i] = new Vector3(x, y, z);
            i++;
        }
    }

    triangles = new int[xSize * zSize * 6];


    //setting triangles and verts for simple quad
    int vert = 0;
    int tris = 0;
    for (int z = 0; z < xSize; z++)
    {
        for (int x = 0; x < xSize; x++)
        {

            triangles[tris + 0] = vert + 0;
            triangles[tris + 1] = vert + xSize + 1;
            triangles[tris + 2] = vert + 1;
            triangles[tris + 3] = vert + 1;
            triangles[tris + 4] = vert + xSize + 1;
            triangles[tris + 5] = vert + xSize + 2;

            vert++;
            tris += 6;

        }
        vert++;
    }
}

void UpdateMesh()
{
    mesh.Clear();

    mesh.vertices = vertices;
    mesh.triangles = triangles;
    mesh.RecalculateNormals();
}

}

谢谢你。

c#
  • 2 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-09-30 05:05:49 +0000 UTC

世界生成脚本不连接对象

  • 0

我编写了一个用于生成体素世界的脚本,其中在生成区域后,该脚本将 1 个块连接到 1 个网格。但这不会发生。该脚本没有将生成的体素分配给 Chunk 父级。为什么以及如何解决它?脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Chunk : MonoBehaviour
{
    public GameObject currentBlockType;

    public int Seed;
    public bool randomizeSeed;

    public float smooth = 0;
    public float multiplier = 0;
    public int cols = 50;
    public int rows = 50;
    public bool CombineChunk;

    private Vector3 myPos;
    private Transform thisObject;

    static private GameObject thisobjscr;

    private void Start()
    {
        thisobjscr = gameObject;
        thisObject = gameObject.transform;
        if(randomizeSeed == true)
        {
            Seed = Random.Range(1, 200);
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        if(other.tag == "gen")
        {
            print("entered");
            generate();
        }
    }



    public void generate()
    {
        myPos = this.transform.position;

        for (int x = 0; x < cols; x++)
        {
            for (int z = 0; z < rows; z++)
            {
                float y = Mathf.PerlinNoise((myPos.x + x) / smooth + Seed, (myPos.z + z) / smooth + Seed) * multiplier;
                y = Mathf.Floor(y);

                GameObject newBlock = GameObject.Instantiate(currentBlockType);
                newBlock.transform.position = new Vector3(myPos.x + x, y, myPos.z + z );


                if (CombineChunk == true)
                {
                    newBlock.transform.SetParent(thisObject);
                    StartCoroutine(TimerForCombineWait());
                }
            }
        }
    }

    IEnumerator TimerForCombineWait()
    {
        CombineChunk = false;
        print("waiting for world stabilization: " + Time.time);
        yield return new WaitForSeconds(1);
        print("world stabilized in " + Time.time);
        Combine();
    }

    public void Combine()
    {
        MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];

        int a = 0;
        while (a < meshFilters.Length)
        {
            combine[a].mesh = meshFilters[a].sharedMesh;
            combine[a].transform = meshFilters[a].transform.localToWorldMatrix;

            meshFilters[a].gameObject.SetActive(false);

            a++;
        }
        transform.GetComponent<MeshFilter>().mesh = new Mesh();
        transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
        transform.gameObject.SetActive(true);

        gameObject.transform.position = new Vector3(0, 0, 0);
    }
}

谢谢你。

c#
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-09-30 00:49:34 +0000 UTC

Chunk.generate() 非静态字段、方法或属性需要对象引用

  • 0

非静态字段、方法或属性 Chunk.generate() 需要对象引用。我想从第一个脚本开始这样做:

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TerrainMain : MonoBehaviour
{
    private void Start()
    {
        Chunk.GEN();
    }
}

GEN 功能正在运行。它已经在第二个脚本中执行了进一步的操作:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Chunk : MonoBehaviour
{
    public GameObject currentBlockType;

    public float smooth = 0;
    public float multiplier = 0;
    public int cols = 50;
    public int rows = 50;
    public bool CombineChunk;

    private Vector3 myPos;
    private Transform thisObject;

    static private GameObject thisobjscr;

    private void Start()
    {
        thisobjscr = gameObject;
        thisObject = gameObject.transform;
    }
    public static void GEN()
    {
        generate();
    }

    public void generate()
    {
        myPos = this.transform.position;

        for (int x = 0; x < cols; x++)
        {
            for (int z = 0; z < rows; z++)
            {
                float y = Mathf.PerlinNoise((myPos.x + x) / smooth, (myPos.z + z) / smooth) * multiplier;
                y = Mathf.Floor(y);

                GameObject newBlock = GameObject.Instantiate(currentBlockType);
                newBlock.transform.position = new Vector3(myPos.x + x, y, myPos.z + z);
                newBlock.transform.SetParent(thisObject);

                if (CombineChunk == true)
                {
                    StartCoroutine(TimerForCombineWait());
                }
            }
        }
    }

    IEnumerator TimerForCombineWait()
    {
        CombineChunk = false;
        print("waiting for world stabilization: " + Time.time);
        yield return new WaitForSeconds(1);
        print("world stabilized in " + Time.time);
        Combine();
    }

    public void Combine()
    {
        MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
        CombineInstance[] combine = new CombineInstance[meshFilters.Length];

        int a = 0;
        while (a < meshFilters.Length)
        {
            combine[a].mesh = meshFilters[a].sharedMesh;
            combine[a].transform = meshFilters[a].transform.localToWorldMatrix;

            meshFilters[a].gameObject.SetActive(false);

            a++;
        }
        transform.GetComponent<MeshFilter>().mesh = new Mesh();
        transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
        transform.gameObject.SetActive(true);

        gameObject.transform.position = new Vector3(0, 0, 0);
    }
}

Unity 仅在 public static void GEN 中抛出错误

谢谢你。

unity3d
  • 1 个回答
  • 10 Views
Martin Hope
cyberfrogg
Asked: 2020-09-04 03:46:53 +0000 UTC

PYTHON ModuleNotFoundError:尽管安装了模块,但没有名为“Image”的模块

  • 0

我要导入图片组件,安装并导入:

import image
text = "Hello, PIL!!!"
color = (0, 0, 120)
img = Image.new('RGB', (100, 50), color)
imgDrawer = ImageDraw.Draw(img)
imgDrawer.text((10, 20), text)
img.save("pil-basic-example.png")

我在谷歌上搜索并没有找到解决方案。PS我有自定义安装路径:A:\Python\

python
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5