第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Unity 中生成“斜坡”對(duì)象的算法

在 Unity 中生成“斜坡”對(duì)象的算法

C#
慕容3067478 2021-06-30 15:03:05
我正在 Unity 中為我的 A 級(jí)計(jì)算機(jī)科學(xué)項(xiàng)目創(chuàng)建一個(gè)基本模擬器。目前,用戶可以通過(guò)選擇相關(guān)工具并單擊并拖動(dòng)來(lái)確定框的兩個(gè)相對(duì)角,從而確定其尺寸來(lái)繪制框(板條箱)對(duì)象。該盒子由一個(gè)單獨(dú)的預(yù)制件組成,該預(yù)制件被實(shí)例化并相應(yīng)地改變其大小。它的代碼如下:void Start () {    boxAnim = boxButton.GetComponent<Animator>();}// Update is called once per framevoid Update(){       //sets the mouseDown and mouseHeld bools and the mouse position Vector3    mouseDown = Input.GetMouseButtonDown(0);    mouseHeld = Input.GetMouseButton(0);    mousePosition = Input.mousePosition;    //checks if the user has started to draw    if (mouseDown && !draw)    {        draw = true;        originalMousePosition = mousePosition;    }    //checking if the user has released the mouse    if (draw && !mouseHeld)    {        finalMousePosition = mousePosition;        draw = false;        if (boxAnim.GetBool("Pressed") == true) //if the box draw button is pressed        {            boxDraw(originalMousePosition, finalMousePosition); //draws crate        }    }}以類似的方式,我希望能夠創(chuàng)建一個(gè)“斜坡”對(duì)象,以便用戶可以單擊并拖動(dòng)以確定基本寬度,然后再次單擊以確定仰角/高度,(斜坡將始終是一個(gè)直角三角形。)問(wèn)題在于我希望將斜坡作為我創(chuàng)建的精靈,而不僅僅是基本的塊顏色。然而,單個(gè)精靈只有一個(gè)仰角,并且沒(méi)有變換能夠改變這一點(diǎn)(據(jù)我所知。)顯然我不想為每個(gè)角度創(chuàng)建不同的精靈,所以有什么我可以做的嗎?我想的解決方案是,是否有某種功能可以改變代碼中矢量圖像的節(jié)點(diǎn),但我很確定這不存在。
查看完整描述

2 回答

?
慕絲7291255

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

我有一個(gè)使用網(wǎng)格和多邊形碰撞器來(lái)解決部分問(wèn)題的方法。我現(xiàn)在有一個(gè)函數(shù)可以創(chuàng)建一個(gè)具有給定寬度和高度的直角三角形以及一個(gè)三角形形狀的碰撞器:


using UnityEngine;

using System.Collections;


public class createMesh : MonoBehaviour {


    public float width = 5f;

    public float height = 5f;


    public PolygonCollider2D polyCollider;


    void Start()

    {

        polyCollider = GetComponent<PolygonCollider2D>();

    }


    // Update is called once per frame

    void Update () {

        TriangleMesh(width, height);

    }


    void TriangleMesh(float width, float height)

    {

        MeshFilter mf = GetComponent<MeshFilter>();

        Mesh mesh = new Mesh();

        mf.mesh = mesh;


        //Verticies

        Vector3[] verticies = new Vector3[3]

        {

            new Vector3(0,0,0), new Vector3(width, 0, 0), new Vector3(0, 

height, 0)

        };


        //Triangles

        int[] tri = new int[3];


        tri[0] = 0;

        tri[1] = 2;

        tri[2] = 1;


        //normals

        Vector3[] normals = new Vector3[3];


        normals[0] = -Vector3.forward;

        normals[1] = -Vector3.forward;

        normals[2] = -Vector3.forward;


        //UVs

        Vector2[] uv = new Vector2[3];


        uv[0] = new Vector2(0, 0);

        uv[0] = new Vector2(1, 0);

        uv[0] = new Vector2(0, 1);


        //initialise

        mesh.vertices = verticies;

        mesh.triangles = tri;

        mesh.normals = normals;

        mesh.uv = uv;


        //setting up collider

        polyCollider.pathCount = 1;


        Vector2[] path = new Vector2[3]

        {

            new Vector2(0,0), new Vector2(0, height), new Vector2(width, 0)

        };


        polyCollider.SetPath(0, path);


    }

}

我只需要將此函數(shù)放入與我繪制框的代碼非常相似的代碼中,以便用戶可以指定寬度和高度。


查看完整回答
反對(duì) 回復(fù) 2021-07-10
  • 2 回答
  • 0 關(guān)注
  • 261 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)