Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.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# 如何将所有linerenderer测试函数置于游戏对象父对象下? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类抽绳:单一行为 { 公共线条渲染器线条渲染器; 公共游戏对象点预置; 公共字符串编号; 私有向量3[]个位置; //在第一帧更新之前调用Start void Start() { 提款编号(0); } //每帧调用一次更新 无效更新() { if(Input.GetKeyDown(“0”)) { 提款编号(0); 数字=“0”; } } 无效提款编号(整数编号) { 如果(数字==0) { 零(); } } 私有无效零() { 位置=新向量3[7]{新向量3(0,0,0), 新矢量3(1,0,0), 新向量3(1,-1,0), 新向量3(1,-2,0), 新向量3(0,-2,0), 新向量3(0,-1,0), 新向量3(0,0,0)}; lineRenderer.positionCount=7; lineRenderer.SetPositions(位置); 对于(int i=0;i_C#_Unity3d - Fatal编程技术网

C# 如何将所有linerenderer测试函数置于游戏对象父对象下? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类抽绳:单一行为 { 公共线条渲染器线条渲染器; 公共游戏对象点预置; 公共字符串编号; 私有向量3[]个位置; //在第一帧更新之前调用Start void Start() { 提款编号(0); } //每帧调用一次更新 无效更新() { if(Input.GetKeyDown(“0”)) { 提款编号(0); 数字=“0”; } } 无效提款编号(整数编号) { 如果(数字==0) { 零(); } } 私有无效零() { 位置=新向量3[7]{新向量3(0,0,0), 新矢量3(1,0,0), 新向量3(1,-1,0), 新向量3(1,-2,0), 新向量3(0,-2,0), 新向量3(0,-1,0), 新向量3(0,0,0)}; lineRenderer.positionCount=7; lineRenderer.SetPositions(位置); 对于(int i=0;i

C# 如何将所有linerenderer测试函数置于游戏对象父对象下? 使用系统集合; 使用System.Collections.Generic; 使用UnityEngine; 公共类抽绳:单一行为 { 公共线条渲染器线条渲染器; 公共游戏对象点预置; 公共字符串编号; 私有向量3[]个位置; //在第一帧更新之前调用Start void Start() { 提款编号(0); } //每帧调用一次更新 无效更新() { if(Input.GetKeyDown(“0”)) { 提款编号(0); 数字=“0”; } } 无效提款编号(整数编号) { 如果(数字==0) { 零(); } } 私有无效零() { 位置=新向量3[7]{新向量3(0,0,0), 新矢量3(1,0,0), 新向量3(1,-1,0), 新向量3(1,-2,0), 新向量3(0,-2,0), 新向量3(0,-1,0), 新向量3(0,0,0)}; lineRenderer.positionCount=7; lineRenderer.SetPositions(位置); 对于(int i=0;i,c#,unity3d,C#,Unity3d,每次我按0键,它都会创建另一个零,但第一个问题是,新的零与第一个零位于同一位置,所以我想将所有的零放在一个父项下,所以每次我按0键,它都会创建一个新的零游戏对象子项,而且新的子项也会处于稍微不同的位置 我想这就是你要找的 using System.Collections; using System.Collections.Generic; using UnityEngine; public class DrawLines : MonoBehaviour { public LineRen

每次我按0键,它都会创建另一个零,但第一个问题是,新的零与第一个零位于同一位置,所以我想将所有的零放在一个父项下,所以每次我按0键,它都会创建一个新的零游戏对象子项,而且新的子项也会处于稍微不同的位置

我想这就是你要找的

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

public class DrawLines : MonoBehaviour
{
    public LineRenderer lineRenderer;
    public GameObject dotPrefab;
    public string numbers;

    private Vector3[] Positions;

    // Start is called before the first frame update
    void Start()
    {
        DrawNumber(0);
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown("0"))
        {
            DrawNumber(0);
            numbers = "0";
        }
    }

    void DrawNumber(int number)
    {
        if (number == 0)
        {
            Zero();
        }
    }

    private void Zero()
    {
        Positions = new Vector3[7] { new Vector3(0, 0, 0),
            new Vector3(1, 0, 0),
            new Vector3(1, -1, 0),
        new Vector3(1,-2,0),
        new Vector3(0,-2,0),
        new Vector3(0,-1,0),
        new Vector3(0,0,0)};

        lineRenderer.positionCount = 7;
        lineRenderer.SetPositions(Positions);

        for (int i = 0; i < Positions.Length; i++)
        {
            var dot = Instantiate(dotPrefab);
            dot.transform.position = Positions[i];
        }
    }
}
private const float LETTER_WIDTH=2f;
公共线条渲染器线条渲染器;
公共游戏对象点预置;
公共字符串编号;
公共转换词锚//父对象,以设置其下的所有字母
私有int currentLetterIndex=0;
私有向量3[]个位置;
//在第一帧更新之前调用Start
void Start()
{
提款编号(0);
}
//每帧调用一次更新
无效更新()
{
if(Input.GetKeyDown(“0”))
{
提款编号(0);
数字=“0”;
}
}
无效提款编号(整数编号)
{
如果(数字==0)
{
零();
}
}
私有无效零()
{
位置=新向量3[7]{新向量3(0,0,0),
新矢量3(1,0,0),
新向量3(1,-1,0),
新向量3(1,-2,0),
新向量3(0,-2,0),
新向量3(0,-1,0),
新向量3(0,0,0)};
//创建一个游戏对象,作为下点的父对象
GameObject字母=新游戏对象(currentLetterIndex.ToString());
letter.transform.parent=WordAnchor;//为单词下的字母设置父级
letter.transform.localPosition=new Vector3(currentLetterIndex*letter_WIDTH,0f,0f);//根据索引移动偏移量
LineRenderer LineRenderInstance=letter.AddComponent();
LineRenderInstance.positionCount=7;
LineRenderInstance.SetPositions(位置);
LineRenderInstance.useWorldSpace=false;
对于(int i=0;i
我想这就是你要找的

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

public class DrawLines : MonoBehaviour
{
    public LineRenderer lineRenderer;
    public GameObject dotPrefab;
    public string numbers;

    private Vector3[] Positions;

    // Start is called before the first frame update
    void Start()
    {
        DrawNumber(0);
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown("0"))
        {
            DrawNumber(0);
            numbers = "0";
        }
    }

    void DrawNumber(int number)
    {
        if (number == 0)
        {
            Zero();
        }
    }

    private void Zero()
    {
        Positions = new Vector3[7] { new Vector3(0, 0, 0),
            new Vector3(1, 0, 0),
            new Vector3(1, -1, 0),
        new Vector3(1,-2,0),
        new Vector3(0,-2,0),
        new Vector3(0,-1,0),
        new Vector3(0,0,0)};

        lineRenderer.positionCount = 7;
        lineRenderer.SetPositions(Positions);

        for (int i = 0; i < Positions.Length; i++)
        {
            var dot = Instantiate(dotPrefab);
            dot.transform.position = Positions[i];
        }
    }
}
private const float LETTER_WIDTH=2f;
公共线条渲染器线条渲染器;
公共游戏对象点预置;
公共字符串编号;
公共转换词锚//父对象,以设置其下的所有字母
私有int currentLetterIndex=0;
私有向量3[]个位置;
//在第一帧更新之前调用Start
void Start()
{
提款编号(0);
}
//每帧调用一次更新
无效更新()
{
if(Input.GetKeyDown(“0”))
{
提款编号(0);
数字=“0”;
}
}
无效提款编号(整数编号)
{
如果(数字==0)
{
零();
}
}
私有无效零()
{
位置=新向量3[7]{新向量3(0,0,0),
新矢量3(1,0,0),
新向量3(1,-1,0),
新向量3(1,-2,0),
新向量3(0,-2,0),
新向量3(0,-1,0),
新向量3(0,0,0)};
//创建一个游戏对象,作为下点的父对象
GameObject字母=新游戏对象(currentLetterIndex.ToString());
letter.transform.parent=WordAnchor;//为单词下的字母设置父级
letter.transform.localPosition=new Vector3(currentLetterIndex*letter_WIDTH,0f,0f);//根据索引移动偏移量
LineRenderer LineRenderInstance=letter.AddComponent();
LineRenderInstance.positionCount=7;
LineRenderInstance.SetPositions(位置);
LineRenderInstance.useWorldSpace=false;
对于(int i=0;i
出现了一个问题。例如,当我按下0三次时,它将在父对象下创建新的0对象,但所有新的0对象都是空的。我想复制linerenderer,因此如果我移动新0的一个位置,我将在游戏中看到两个零。我的意思是,当我拖动其中一个0时,它不会移动linerenderer线。我希望能够将每个绘制零的位置更改为一个对象。哦,如果您希望能够在游戏中移动线条渲染,您需要将所有位置移动x个数量,或者您可以将线条渲染器设置为useWorldSpace=false。这是一个问题。例如,当我按下0三次时,它将在父对象下创建新的0对象,但所有新的0对象都是空的。我想复制linerenderer,因此如果我移动新0的一个位置,我将在游戏中看到两个零。我的意思是,当我拖动其中一个0时,它不会移动linerenderer线。我希望能够改变每个画出的零作为一个对象的位置。哦,如果你想在游戏中移动线渲染,你需要将所有的位置移动x a