DroneSimulator/Assets/Scripts/Drone/Drone.cs

46 lines
1.2 KiB
C#

using System;
using UnityEngine;
[RequireComponent (typeof(Rigidbody))]
public class Drone : MonoBehaviour
{
[SerializeField] private float ForseRotate;
[SerializeField] private Motor _motorFR;
[SerializeField] private Motor _motorFL;
[SerializeField] private Motor _motorBR;
[SerializeField] private Motor _motorBL;
[SerializeField] private bool _enableMotors = false;
[SerializeField] private float _heightStabilizer = 50;
private Rigidbody _rigidbody;
private void Awake()
{
_rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
if (_enableMotors)
{
_motorFR.SetThrust(InputController.LeftY);
_motorFL.SetThrust(InputController.LeftY);
_motorBL.SetThrust(InputController.LeftY);
_motorBR.SetThrust(InputController.LeftY);
}
}
private void FixedUpdate()
{
if (_enableMotors)
{
transform.Rotate(Vector3.right * InputController.RightY * ForseRotate);
transform.Rotate(Vector3.up * InputController.LeftX * ForseRotate);
transform.Rotate(Vector3.back * InputController.RightX * ForseRotate);
}
}
}