#if UNITY_5_3_OR_NEWER using UnityEngine; namespace RoboidControl.Unity { public class Motor : Thing { /// /// Create the Unity representation /// /// The core motor /// The Unity representation of a motor public static Motor Create(RoboidControl.Motor core) { GameObject prefab = (GameObject)Resources.Load("Motor"); if (prefab != null) { // Use resource prefab when available GameObject gameObj = Instantiate(prefab); Motor component = gameObj.GetComponent(); if (component != null) component.core = core; return component; } else { // Fallback implementation GameObject gameObj = new(core.name); Motor component = gameObj.AddComponent(); component.Init(core); Rigidbody rb = gameObj.AddComponent(); rb.isKinematic = true; return component; } } public float rotationSpeed = 0.0f; protected override void HandleBinary() { RoboidControl.Motor coreMotor = core as RoboidControl.Motor; this.rotationSpeed = coreMotor.targetSpeed; } protected override void Update() { base.Update(); // We rotate the first child of the motor, which should be the axle. if (this.transform.childCount > 0) { this.transform.GetChild(0).Rotate(360 * this.rotationSpeed, 0, 0); } } } } #endif