View difference between Paste ID: 9raT38d6 and 85qjZp8R
SHOW: | | - or go back to the newest paste.
1
using UnityEngine;
2
using System.Collections;
3
4
public class Graph : MonoBehaviour {
5
    
6
    Vector3 zero = new Vector3(0, 0, 0);
7
    Vector3 zero2 = new Vector3(0, 0, 0);
8
    //Line 1
9
    string slp;
10-
	string ynt;
10+
    string ynt;
11
    //Line 2
12-
	string slp2;
12+
    string slp2;
13-
	string ynt2;
13+
    string ynt2;
14
	
15
    string currentMenu = "GUI";
16-
	string currentMenu = "GUI";
16+
    public GameObject line1;
17-
	public GameObject line1;
17+
    public GameObject line2;
18-
	public GameObject line2;
18+
19
    void Start() {
20-
	void Start() {
20+
	slp = "";
21-
		slp = "";
21+
	ynt = "";
22-
		ynt = "";
22+
	slp2 = "";
23
	ynt2 = "";
24-
		slp2 = "";
24+
    }
25-
		ynt2 = "";
25+
26
    void OnGUI() {
27
	if(currentMenu == "GUI")
28-
	void OnGUI() {
28+
	    GraphUI();
29-
		if(currentMenu == "GUI")
29+
30-
			GraphUI();
30+
31
    void GraphUI() {
32
33-
	void GraphUI() {
33+
	GUI.Box(new Rect(0, 0, 300, Screen.height), "Graphing Calculator");
34
	//Line 1
35-
		GUI.Box(new Rect(0, 0, 300, Screen.height), "Graphing Calculator");
35+
	GUI.Label(new Rect(10, 30, 100, 20), "Y-Intercept 1");
36-
		//Line 1
36+
	ynt = GUI.TextField(new Rect(10, 50, 280, 60), ynt);
37-
		GUI.Label(new Rect(10, 30, 100, 20), "Y-Intercept 1");
37+
	GUI.Label(new Rect(10, 120, 100, 20), "Slope 1");
38-
		ynt = GUI.TextField(new Rect(10, 50, 280, 60), ynt);
38+
	slp = GUI.TextField(new Rect(10, 140, 280, 60), slp);
39-
		GUI.Label(new Rect(10, 120, 100, 20), "Slope 1");
39+
40-
		slp = GUI.TextField(new Rect(10, 140, 280, 60), slp);
40+
41-
		//Line 2
41+
	GUI.Label(new Rect(10, 240, 100, 20), "Y-Intercept 2");
42
	ynt2 = GUI.TextField(new Rect(10, 260, 280, 60), ynt2);
43-
		GUI.Label(new Rect(10, 240, 100, 20), "Y-Intercept 2");
43+
	GUI.Label(new Rect(10, 330, 100, 20), "Slope 2");
44-
		ynt2 = GUI.TextField(new Rect(10, 260, 280, 60), ynt2);
44+
	slp2 = GUI.TextField(new Rect(10, 350, 280, 60), slp2);
45-
		GUI.Label(new Rect(10, 330, 100, 20), "Slope 2");
45+
46-
		slp2 = GUI.TextField(new Rect(10, 350, 280, 60), slp2);
46+
	if(GUI.Button(new Rect(10, 420, 280, 60), "Calculate and Graph")) {
47
	    if((slp != null && slp != "") && (ynt != null && ynt != "")) {
48-
		if(GUI.Button(new Rect(10, 420, 280, 60), "Calculate and Graph")) {
48+
		Calculate(slp, ynt, slp2, ynt2);
49-
			if((slp != null && slp != "") && (ynt != null && ynt != "")) {
49+
	    } else {
50-
				Calculate(slp, ynt, slp2, ynt2);
50+
		Debug.LogWarning("Parameters Not Complete");
51-
			} else {
51+
	    }
52-
				Debug.LogWarning("Parameters Not Complete");
52+
53-
			}
53+
54-
		}
54+
	if(GUI.Button(new Rect(10, Screen.height - 70, 280, 60), "Reset Graph")) {
55
	    slp = "";
56-
		if(GUI.Button(new Rect(10, Screen.height - 70, 280, 60), "Reset Graph")) {
56+
	    ynt = "";
57-
			slp = "";
57+
	    slp2 = "";
58-
			ynt = "";
58+
            ynt2 = "";
59-
			slp2 = "";
59+
60-
			ynt2 = "";
60+
	    GameObject[] points = GameObject.FindGameObjectsWithTag("GraphPoint");
61
	    foreach (GameObject target in points) {
62-
			GameObject[] points = GameObject.FindGameObjectsWithTag("GraphPoint");
62+
        	GameObject.Destroy(target);
63-
			foreach (GameObject target in points) {
63+
    	    }
64-
        		GameObject.Destroy(target);
64+
65-
    		}
65+
    }
66-
		}
66+
67
    //Line 1
68
    void Calculate(string sl, string yt, string sl2, string yt2) {
69
	int nextNumber = 1;
70-
	void Calculate(string sl, string yt, string sl2, string yt2) {
70+
	StartCoroutine(Calculate2(sl2, yt2));
71-
		int nextNumber = 1;
71+
	float slope = float.Parse(sl);
72-
		StartCoroutine(Calculate2(sl2, yt2));
72+
	float yint = float.Parse(yt);
73-
		float slope = float.Parse(sl);
73+
	float y = yint;
74-
		float yint = float.Parse(yt);
74+
	float x = slope;
75-
		float y = yint;
75+
	zero.y = y;
76-
		float x = slope;
76+
	zero.x = 0; 
77-
		zero.y = y;
77+
78-
		zero.x = 0; 
78+
79
            Object redPoint = Instantiate(line1, zero, Quaternion.identity);
80
            redPoint.name = "Red" + nextNumber;
81
            nextNumber++;
82
            zero.y = zero.y + slope;
83
            zero.x = zero.x += 1;
84
        }
85
86
        zero.y = 0;
87
        zero.x = 0;
88
        nextNumber = 1;
89
        //CalculateAngle(GameObject.Find("Red1"), GameObject.Find("Red2"));
90
        CalculateAngle(GameObject.Find("Red1"), GameObject.Find("Red2"));
91
    }
92
93
    //Line 2
94
    IEnumerator Calculate2(string sl, string yt) {
95
	yield return new WaitForSeconds(0.0f);
96-
	IEnumerator Calculate2(string sl, string yt) {
96+
	int nextNumber = 1;
97-
		yield return new WaitForSeconds(0.0f);
97+
	float slope = float.Parse(sl);
98-
		int nextNumber = 1;
98+
	float yint = float.Parse(yt);
99-
		float slope = float.Parse(sl);
99+
	float y = yint;
100-
		float yint = float.Parse(yt);
100+
	float x = slope;
101-
		float y = yint;
101+
	zero2.y = y;
102-
		float x = slope;
102+
	zero2.x = 0; 
103-
		zero2.y = y;
103+
104-
		zero2.x = 0; 
104+
105
            Object yellowPoint = Instantiate(line2, zero2, Quaternion.identity);
106
            yellowPoint.name = "Yellow" + nextNumber;
107
            nextNumber++;
108
            zero2.y = zero2.y + slope;
109
            zero2.x = zero2.x += 1;
110
        }
111
        zero2.y = 0;
112
        zero2.x = 0;
113
		nextNumber = 1;
114
    }
115
116
    void CalculateAngle(GameObject x, GameObject y) {
117
	float xDis = y.transform.position.x - x.transform.position.x;
118-
	void CalculateAngle(GameObject x, GameObject y) {
118+
	float yDis = y.transform.position.y - x.transform.position.y;
119-
		float xDis = y.transform.position.x - x.transform.position.x;
119+
120-
		float yDis = y.transform.position.y - x.transform.position.y;
120+
	Debug.Log(xDis + " : " + yDis);
121
    }
122-
		Debug.Log(xDis + " : " + yDis);
122+