*
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class ElectronicSpeedController : MonoBehaviour {
|
||||
public Motor motor;
|
||||
public bool inverseDirection;
|
||||
|
||||
[Range(0, 1)]
|
||||
public float inputSpeed;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
|
||||
}
|
||||
|
||||
void OnDrawGizmos(){
|
||||
AdvancedGizmo.CircleArrow (0.1f, inverseDirection ? -270 : 270, 37, AdvancedGizmo.CircleCloseType.None, motor.transform.localToWorldMatrix);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
inputSpeed = Mathf.Clamp01 (inputSpeed);
|
||||
|
||||
if (motor != null) {
|
||||
motor.speed = motor.maxRpm * inputSpeed * (inverseDirection ? -1.0f : 1.0f);
|
||||
var rps = motor.speed / 60.0f;
|
||||
var rotateAngle = rps * 360.0f * Time.deltaTime;
|
||||
motor.rotor.transform.Rotate(0, 0, rotateAngle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user