简体   繁体   English

更改游戏对象,当速度计的角度发生变化时

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

I have a car speedomeeter from 0-300 km/h.我有一个 0-300 公里/小时的汽车速度计。 When I am at 80km/hi want to change a gameObject in the background of my speedometer.当我以 80 公里/嗨的速度行驶时,我想在我的车速表背景中更改一个游戏对象。 I have different angles (z-rotation) when the speed is changing.当速度变化时,我有不同的角度(z 旋转)。 Is there any option to get access to the angle and enable new objects like:是否有任何选项可以访问角度并启用新对象,例如:

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

I am a beginner and I am not sure how to achieve this.我是初学者,我不知道如何实现这一点。

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