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

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

大括號(hào)在 C# Unity 中無法正常工作

大括號(hào)在 C# Unity 中無法正常工作

C#
斯蒂芬大帝 2022-12-24 12:41:24
我正在制作一個(gè)統(tǒng)一游戲,然后我腳本中的花括號(hào)變得愚蠢。他們都搞砸了,我不知道我做錯(cuò)了什么。這是我的腳本: ps:我正在使用 visual studiousing System.Collections;using System.Collections.Generic;using UnityEngine;public class MoveSript : MonoBehaviour {    public GameObject myObject;    // Use this for initialization    private Vector3 direction = new Vector3(0, 0, 0);    // Update is called once per frame    private float speed = 40f;    void Start() { // error here? --> "} expected"        private Camera cam = Camera.main;        private float height = 2f * cam.orthographicSize;        private float width = height * cam.aspect;    } // i close it here, but it closes the mono beh. class instead?    void Update () {        int y = 0;        int x = 0;        if (Input.GetKey("up"))        {            y = 1;        }        if (Input.GetKey("down"))        {            y = -1;        }        if (Input.GetKey("right"))        {            x = 1;        }        if (Input.GetKey("left"))        {            x = -1;        }        direction = new Vector3(x, y, 0);        myObject.transform.position += direction.normalized*speed*Time.deltaTime;    }}我究竟做錯(cuò)了什么?感謝您的提前!
查看完整描述

1 回答

?
慕桂英3389331

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

您不能在方法內(nèi)部定義的局部變量中定義可訪問性。它應(yīng)該是


private void Start() 

{

    var cam = Camera.main;

    var height = 2f * cam.orthographicSize;

    var width = height * cam.aspect;


    // Makes only sense if you now use the width

    // and/or other values for something

}

或者在類級(jí)別定義它們(例如,稍后也可以在其他方法中訪問它們),例如


private Camera cam;

private float height;

private float width;


private void Start() 

{

    cam = Camera.main;

    height = 2f * cam.orthographicSize;

    width = height * cam.aspect;

}


查看完整回答
反對(duì) 回復(fù) 2022-12-24
  • 1 回答
  • 0 關(guān)注
  • 94 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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