using System.Collections; using System.Collections.Generic; using UnityEngine; public class IMU : MonoBehaviour { public float speed = 5f; public float multipler = 2; private int m_T = 0; // private int m_M = 0; private string s_T = ""; private string s_M = ""; // Start is called before the first frame update void Start() { } public void SliderChange (float newValue) { multipler = (newValue/20); } // Update is called once per frame void Update() { float Xtemp = Input.acceleration.x; float Ytemp = Input.acceleration.y; float xVector = multipler*Xtemp*100; float yVector = multipler*Ytemp*100; transform.Translate(-speed*Xtemp * Time.deltaTime,0,0); transform.Translate(-speed*Ytemp * Time.deltaTime,0,0); s_T = ""; s_M = ""; if (Mathf.Abs(xVector)<50) { m_T = 0; s_M = "[0,0,0,0,0,0,0]"; } else if (xVector < 50) { m_T = 60; s_M = "[2,1,0,0,0,0,0]"; } else { m_T = 60; s_M = "[1,2,0,0,0,0,0]"; } s_T += m_T.ToString(); for (int ii = 0; ii < 6; ii++) { s_T += ","; s_T += m_T.ToString(); } string mssg = "{\"pType\":7,\"m_T\":[" + s_T + "],\"m_M\":" + s_M + "}"; gameObject.GetComponent ().SendValue (mssg); } }