mirror of
https://github.com/BotChain-Robots/ui.git
synced 2026-07-08 15:07:22 +02:00
switch from Unity version control to git
This commit is contained in:
41
Assets/DCMotorControlPanel.cs
Normal file
41
Assets/DCMotorControlPanel.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DCMotorControlPanel : MonoBehaviour
|
||||
{
|
||||
public TMP_InputField degreesInputField;
|
||||
public TMP_Dropdown directionDropdown;
|
||||
public Button rotateButton;
|
||||
|
||||
private DCMotorModule currentDCModule;
|
||||
|
||||
public void Initialize(DCMotorModule DCModule)
|
||||
{
|
||||
currentDCModule = DCModule;
|
||||
gameObject.SetActive(true);
|
||||
rotateButton.onClick.RemoveAllListeners();
|
||||
rotateButton.onClick.AddListener(HandleRotateClicked);
|
||||
}
|
||||
|
||||
public void HandleRotateClicked()
|
||||
{
|
||||
// Parse degrees
|
||||
if (!float.TryParse(degreesInputField.text, out float degrees))
|
||||
{
|
||||
Debug.LogWarning("Invalid degree input");
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine direction
|
||||
int direction = directionDropdown.value == 0 ? 1 : -1;
|
||||
currentDCModule.Rotate(degrees, direction);
|
||||
}
|
||||
|
||||
public void HidePanel()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user