Created
February 12, 2015 19:24
-
-
Save DV8FromTheWorld/02cab94ac50737cef1ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using System.Collections.Generic; | |
| public class pendulumVelocity : MonoBehaviour | |
| { | |
| List<float> list = new List<float> (); | |
| public int numToGraph = 128; | |
| public Transform bar; | |
| public Transform[] bars; | |
| public Transform barContainer; | |
| // Use this for initialization | |
| void Awake () | |
| { | |
| bars = new Transform[numToGraph]; | |
| createGraph (); | |
| //Screen.lockCursor = true; | |
| } | |
| // Update is called once per frame | |
| void FixedUpdate () | |
| { | |
| float velocityMag = rigidbody.velocity.magnitude; | |
| graphVelocity (velocityMag); | |
| } | |
| void graphVelocity (float velocity) | |
| { | |
| if (list.Count > numToGraph) { | |
| //list.Remove(0); | |
| list.RemoveAt (0); | |
| } | |
| list.Add (velocity); | |
| printList (list); | |
| } | |
| void printList (List<float> list) | |
| { | |
| for (int i = 0; i < numToGraph; i++) { | |
| //double h = (double)(list[i]); | |
| float height = list [i]; | |
| bars [i].localScale = new Vector3 (1, height, 1); | |
| } | |
| } | |
| void createGraph () | |
| { | |
| for (int i = 0; i < numToGraph; i++) { | |
| Vector3 pos = barContainer.transform.position; | |
| pos.x +=i; | |
| bars [i] = Instantiate (bar, pos, Quaternion.identity) as Transform; | |
| bars [i].parent = barContainer; | |
| list.Add (0); | |
| } | |
| barContainer.transform.localScale = new Vector3 (2f, .48f, .12f); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment