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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Input.GetkeyDown 在沒有按鈕按下的情況下返回 true

Input.GetkeyDown 在沒有按鈕按下的情況下返回 true

C#
牛魔王的故事 2022-10-23 16:24:18
我正在制作一個系統(tǒng),您可以在其中按下某個鍵,它將在您的鼠標位置放置一個對象。每次按下“1”鍵時,它都應該將其放在鼠標位置,但由于某種原因,每一幀都Input.GetKeyDown("Alpha1");被注冊為 true,因此無論我移動鼠標,無論我按什么,它都會將塊向下放置。最近經(jīng)常發(fā)生這種情況,我似乎找不到任何答案。using UnityEngine;public class CubePlacer : MonoBehaviour{    private Grid grid;    public KeyCode place;    private void Awake()    {        grid = FindObjectOfType<Grid>();    }    private void Update()    {        if (Input.GetKeyDown(place)) ;        {            RaycastHit hitInfo;            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);            if (Physics.Raycast(ray, out hitInfo))            {                PlaceCubeNear(hitInfo.point);            }        }    }    private void PlaceCubeNear(Vector3 clickPoint)    {        var finalPosition = grid.GetNearestPointOnGrid(clickPoint);        GameObject.CreatePrimitive(PrimitiveType.Cube).transform.position = finalPosition;        //GameObject.CreatePrimitive(PrimitiveType.Sphere).transform.position = nearPoint;    }}
查看完整描述

1 回答

?
拉莫斯之舞

TA貢獻1820條經(jīng)驗 獲得超10個贊

if (Input.GetKeyDown(place)) ; // <--- remove this semi colon

        {

            RaycastHit hitInfo;

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);


            if (Physics.Raycast(ray, out hitInfo))

            {

                PlaceCubeNear(hitInfo.point);

            }

        }

您需要刪除 If 語句后的分號。每次Update()調用該方法時,它都會終止該行并導致塊隨后執(zhí)行。


查看完整回答
反對 回復 2022-10-23
  • 1 回答
  • 0 關注
  • 134 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號