简体   繁体   中英

Change GameObject, when angle of a speedometer is changing

I have a car speedomeeter from 0-300 km/h. When I am at 80km/hi want to change a gameObject in the background of my speedometer. I have different angles (z-rotation) when the speed is changing. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM