37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
#if UNITY_5_3_OR_NEWER
|
|
using UnityEngine;
|
|
|
|
namespace Passer.Control.Unity {
|
|
|
|
public class Thing : MonoBehaviour {
|
|
|
|
protected Core.Thing core;
|
|
|
|
protected void CreateThing(Core.Thing thing) {
|
|
SiteServer siteServer = FindAnyObjectByType<SiteServer>();
|
|
if (siteServer == null) {
|
|
Debug.LogWarning("No site server found");
|
|
return;
|
|
}
|
|
|
|
core = thing;
|
|
siteServer.site.Add(thing);
|
|
}
|
|
|
|
protected virtual void Update() {
|
|
if (core == null)
|
|
return;
|
|
|
|
if (core.linearVelocity != null) {
|
|
Vector3 direction = Quaternion.AngleAxis(core.linearVelocity.direction.horizontal, Vector3.up) * Vector3.forward;
|
|
this.transform.Translate(direction * core.linearVelocity.distance * Time.deltaTime);
|
|
}
|
|
if (core.angularVelocity != null) {
|
|
Vector3 axis = Quaternion.AngleAxis(core.angularVelocity.direction.horizontal, Vector3.up) * Vector3.forward;
|
|
this.transform.Rotate(axis, core.angularVelocity.distance * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
#endif |