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

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

如何讓一個(gè)游戲?qū)ο蠖ㄎ黄渌螒驅(qū)ο蟮奈恢貌⒏嬖V它們的顏色?

如何讓一個(gè)游戲?qū)ο蠖ㄎ黄渌螒驅(qū)ο蟮奈恢貌⒏嬖V它們的顏色?

C#
嗶嗶one 2022-11-13 15:52:40
我有 2 個(gè)游戲?qū)ο螅粋€(gè)藍(lán)色和一個(gè)紅色。兩人都在場景中跑來跑去,鏡頭受限,所以他們不能通過某個(gè)區(qū)域。如果可能的話,我也想知道如何在對角線上移動(dòng)它們。這是我的全部代碼。public Transform Objectup;public Transform Objectdown;public Transform Objectright;public Transform Objectleft;public DirectionGameObject direction;public int speed = 2;public enum DirectionGameObject{    Right,    Left,    Up,    Down}// Start is called before the first frame updatevoid Start(){    direction = SortdirectionGameObject(direction);}// Update is called once per framevoid Update(){    Destroy();    if(direction == DirectionGameObject.Right)    {        transform.Translate(Vector3.right * Time.deltaTime * speed);        if(transform.position.x >= Objectright.position.x)        {            direction = SortdirectionGameObject(direction);        }    }    if(direction == DirectionGameObject.Left)    {        transform.Translate(Vector3.left * Time.deltaTime * speed);        if(transform.position.x <= Objectleft.position.x)        {            direction = SortdirectionGameObject(direction);        }    }    if(direction == DirectionGameObject.Up)    {        transform.Translate(Vector3.up * Time.deltaTime * speed);        if(transform.position.y >= Objectup.position.y)        {            direction = SortdirectionGameObject(direction);        }    }    if(direction == DirectionGameObject.Down)    {        transform.Translate(Vector3.down * Time.deltaTime * speed);        if(transform.position.y <= Objectdown.position.y)        {            direction = SortdirectionGameObject(direction);        }    }}private DirectionGameObject SortdirectionGameObject(DirectionGameObject maindirection){    DirectionGameObject directionSorted = maindirection;    do{        int newDirection = Random.Range((int)DirectionGameObject.Right, (int)DirectionGameObject.Down + 1);        directionSorted = (DirectionGameObject)newDirection;    } while (maindirection == directionSorted);    return directionSorted;}void Destroy(){    Destroy(gameObject,120.0f);}當(dāng)我按下 G 和 V 時(shí),我需要在控制臺上顯示它們的顏色和位置。C#unity3d
查看完整描述

1 回答

?
守候你守候我

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

您要查找的游戲?qū)ο蟮念伾珜傩晕挥阡秩酒鹘M件的材質(zhì)中。


可以這樣引用:


gameObject.GetComponent<Renderer>().material.color

為了獲得 GameObject 的 Renderer 組件,您必須擁有對它的引用,例如:


GameObject object1;

GameObject object2;

然后,您可以像這樣獲取每個(gè)對象的顏色:


Color color1 = object1.GetComponent<Renderer>().material.color;

然后你可以像這樣檢查顏色的值:


if (color1 == Color.red){


    // Do something


}

或者,如果你想在控制臺顯示它們的顏色:


Debug.Log(color1);

顏色存儲為 4 個(gè)浮點(diǎn)值,因此如果要輸出“顏色為紅色”或“顏色為藍(lán)色”,則需要進(jìn)行等價(jià)檢查,就像我在上面提供的“// 做某事”注釋中一樣。


查看完整回答
反對 回復(fù) 2022-11-13
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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