簡體   English   中英

更改游戲對象,當速度計的角度發生變化時

[英]Change GameObject, when angle of a speedometer is changing

我有一個 0-300 公里/小時的汽車速度計。 當我以 80 公里/嗨的速度行駛時,我想在我的車速表背景中更改一個游戲對象。 當速度變化時,我有不同的角度(z 旋轉)。 是否有任何選項可以訪問角度並啟用新對象,例如:

if(angle > value) // enable a new object

我是初學者,我不知道如何實現這一點。

You can simply add the gameObject in your scene in the right positions and disable then with the little **check** at the top of the inspector.

Inside the script, you can then call these objects:

    public GameObject number1;
    public GameObject number2;

And then drag the invisible objects from the **hierarchy** inside the cell of the script inside your object inspector.

Then you should put some ifs and set them active:

 

    if(angle < 20)
    { number1.setActive(true);
    number2.setActive(false);
    }
    else if(angle >20)
    { number1.setActive(true);
    number2.setActive(true);
    }

Remember that you can set the objects active in the **edit** view to be able to manage them and put in the `Start()` a simple line where you `.setActive(false)` so when you press play they start disabled

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM