Loop function on button press? Unity3d C#

前端 未结 2 973
时光说笑
时光说笑 2021-01-14 12:01

So, I have an object. When I press Spin Button, I want it to spin. When I press Stop button, I want it to stop.

It spins fine when its in void Update, but when its i

2条回答
  •  一向
    一向 (楼主)
    2021-01-14 12:32

    Following is a simple class that start and stops spinning an object using two buttons, I hope it makes a starting point of what you are trying to achieve.

    public class TestSpin : MonoBehaviour
    {
        public float speed = 500f;
        public Button starter;
        public Button stopper;
    
        bool IsRotating = false;
    
        void Start()
        {
    
            Button btn = starter.GetComponent

提交回复
热议问题