Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在标签上的字符上拾取2个字符串_C#_Unity3d - Fatal编程技术网

C# 如何在标签上的字符上拾取2个字符串

C# 如何在标签上的字符上拾取2个字符串,c#,unity3d,C#,Unity3d,这就是我游戏中的错误,当玩家与物体碰撞时,会改变网格,索引在上面,每当它与标签10碰撞时,下一个是2,应该是11,依此类推 看看我的剧本: public void OnTriggerEnter(Collider other) { if (Regex.IsMatch(other.gameObject.tag, "^(Cube|Sphere|Prism|[A-Z]|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22

这就是我游戏中的错误,当玩家与物体碰撞时,会改变网格,索引在上面,每当它与标签10碰撞时,下一个是2,应该是11,依此类推

看看我的剧本:

public void OnTriggerEnter(Collider other)
    {
        if (Regex.IsMatch(other.gameObject.tag, "^(Cube|Sphere|Prism|[A-Z]|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30) "))    //If player collides with an obstacle
        {
            string indicatorCompareTag = "w";

            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                indicatorCompareTag = playerMesh.mesh.name;
            }
            else if (Application.platform == RuntimePlatform.Android)
            {
                indicatorCompareTag = gameObject.name + " Instance";
            }

            print("Player Mesh name : " + indicatorCompareTag);
            print("Collide tag name : " + other.transform.tag);

            print(playerMesh.mesh.name + " compare tag with " + other.transform.tag + " ? " + other.CompareTag(playerMesh.mesh.name));
            if (other.CompareTag(indicatorCompareTag))      //If the collided gameObject has the same mesh as the player
            {
                Camera.main.GetComponent<Animation>().Play();
                for (int i = 0; i < meshes.Length; i++)
                {
                    print("Ganti");
                    if (meshes[i].name == other.transform.tag[0].ToString() || meshes[i].name== other.transform.tag.Substring(0).ToString())
                    {
                        score.isRighPath = true;
                        other.GetComponent<AudioSource>().Play();
                        audio.play("SwithcedShape");
                        score.IncrementScore();
                        StartCoroutine(Hit());
                        playerMesh.mesh = meshes[i + 1];       //Changes the player's mesh
                        gameObject.name = meshes[i + 1].name;
                        if (indtX >= allAlphabets.Count)
                            indtX = 0;
                        else
                            indtX++;
                        Alphabetconfig();
                    }

                }
                GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
                //FindObjectOfType<ScoreManager>().IncrementScore();      //Increments score
                //Plays Colides
            }
对于带有索引的“更改网格”,当网格名称与标记相同时,将更改网格过滤器

 if (other.CompareTag(indicatorCompareTag))      //If the collided gameObject has the same mesh as the player
            {
                Camera.main.GetComponent<Animation>().Play();
                for (int i = 0; i < meshes.Length; i++)
                {
                    print("Ganti");
                    if (meshes[i].name == other.transform.tag[0].ToString())
                    {
                        score.isRighPath = true;
                        other.GetComponent<AudioSource>().Play();
                        audio.play("SwithcedShape");
                        score.IncrementScore();
                        StartCoroutine(Hit());
                        playerMesh.mesh = meshes[i + 1];       //Changes the player's mesh
                        gameObject.name = meshes[i + 1].name;
                        if (indtX >= allAlphabets.Count)
                            indtX = 0;
                        else
                            indtX++;
                        Alphabetconfig();
                    }

 public void Alphabetconfig()
    {
        activeAlphabets.Clear();
        for (int i = indtX; i <= indtX + 4; i++)
        {
            activeAlphabets.Add(allAlphabets[i]);
        }
    }

if(other.CompareTag(indicatorCompareTag))//如果碰撞的游戏对象与玩家具有相同的网格
{

Camera.main.GetComponent

您不太清楚要归档什么。我认为广泛使用标签和修改游戏对象名称不是最佳做法

根据您给出的描述,这可能是错误:
mesh[i].name==other.transform.tag[0]

这只提供标记名的第一个字符,因此对于下一个网格,
10
将被截断为
1
,然后递增为
2

您可能希望使用
other.transform.tag
来处理整个标记名,或者剪切不需要的部分,如下所示:

tagdigits = Regex.Replace(other.transform.tag, "[^0-9]", ""); // only digits remain

我们真的不清楚这里的问题陈述是什么。请描述所期望的行为,然后描述现在正在发生的行为。为什么你要将标签与名字进行比较?@derHugo只是个人观点,实际上在我看来,这会更容易,但不是全部
tagdigits = Regex.Replace(other.transform.tag, "[^0-9]", ""); // only digits remain