Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Graph : MonoBehaviour {
- Vector3 zero = new Vector3(0, 0, 0);
- Vector3 zero2 = new Vector3(0, 0, 0);
- //Line 1
- string slp;
- string ynt;
- //Line 2
- string slp2;
- string ynt2;
- string currentMenu = "GUI";
- public GameObject line1;
- public GameObject line2;
- void Start() {
- slp = "";
- ynt = "";
- slp2 = "";
- ynt2 = "";
- }
- void OnGUI() {
- if(currentMenu == "GUI")
- GraphUI();
- }
- void GraphUI() {
- GUI.Box(new Rect(0, 0, 300, Screen.height), "Graphing Calculator");
- //Line 1
- GUI.Label(new Rect(10, 30, 100, 20), "Y-Intercept 1");
- ynt = GUI.TextField(new Rect(10, 50, 280, 60), ynt);
- GUI.Label(new Rect(10, 120, 100, 20), "Slope 1");
- slp = GUI.TextField(new Rect(10, 140, 280, 60), slp);
- //Line 2
- GUI.Label(new Rect(10, 240, 100, 20), "Y-Intercept 2");
- ynt2 = GUI.TextField(new Rect(10, 260, 280, 60), ynt2);
- GUI.Label(new Rect(10, 330, 100, 20), "Slope 2");
- slp2 = GUI.TextField(new Rect(10, 350, 280, 60), slp2);
- if(GUI.Button(new Rect(10, 420, 280, 60), "Calculate and Graph")) {
- if((slp != null && slp != "") && (ynt != null && ynt != "")) {
- Calculate(slp, ynt, slp2, ynt2);
- } else {
- Debug.LogWarning("Parameters Not Complete");
- }
- }
- if(GUI.Button(new Rect(10, Screen.height - 70, 280, 60), "Reset Graph")) {
- slp = "";
- ynt = "";
- slp2 = "";
- ynt2 = "";
- GameObject[] points = GameObject.FindGameObjectsWithTag("GraphPoint");
- foreach (GameObject target in points) {
- GameObject.Destroy(target);
- }
- }
- }
- //Line 1
- void Calculate(string sl, string yt, string sl2, string yt2) {
- int nextNumber = 1;
- StartCoroutine(Calculate2(sl2, yt2));
- float slope = float.Parse(sl);
- float yint = float.Parse(yt);
- float y = yint;
- float x = slope;
- zero.y = y;
- zero.x = 0;
- for(int i = 0;i < 5;i++) {
- Object redPoint = Instantiate(line1, zero, Quaternion.identity);
- redPoint.name = "Red" + nextNumber;
- nextNumber++;
- zero.y = zero.y + slope;
- zero.x = zero.x += 1;
- }
- zero.y = 0;
- zero.x = 0;
- nextNumber = 1;
- //CalculateAngle(GameObject.Find("Red1"), GameObject.Find("Red2"));
- CalculateAngle(GameObject.Find("Red1"), GameObject.Find("Red2"));
- }
- //Line 2
- IEnumerator Calculate2(string sl, string yt) {
- yield return new WaitForSeconds(0.0f);
- int nextNumber = 1;
- float slope = float.Parse(sl);
- float yint = float.Parse(yt);
- float y = yint;
- float x = slope;
- zero2.y = y;
- zero2.x = 0;
- for(int i = 0;i < 5;i++) {
- Object yellowPoint = Instantiate(line2, zero2, Quaternion.identity);
- yellowPoint.name = "Yellow" + nextNumber;
- nextNumber++;
- zero2.y = zero2.y + slope;
- zero2.x = zero2.x += 1;
- }
- zero2.y = 0;
- zero2.x = 0;
- nextNumber = 1;
- }
- void CalculateAngle(GameObject x, GameObject y) {
- float xDis = y.transform.position.x - x.transform.position.x;
- float yDis = y.transform.position.y - x.transform.position.y;
- Debug.Log(xDis + " : " + yDis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement