Raphafrei

Bhaskara

Mar 12th, 2017
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class Bhaskara : MonoBehaviour {
  8.  
  9.     [Header("X")]
  10.     public int x;
  11.     private string Sx;
  12.     public Text Ix;
  13.  
  14.     [Header("Y")]
  15.     public int y;
  16.     private string Sy;
  17.     public Text Iy;
  18.  
  19.     [Header("Z")]
  20.     public int z;
  21.     private string Sz;
  22.     public Text Iz;
  23.  
  24.     [Header("Result")]
  25.     public int x1;
  26.     public Text Ix1;
  27.  
  28.     public int x2;
  29.     public Text Ix2;
  30.  
  31.     public int delta;
  32.     public float squareDelta;
  33.     public int sqrDelta;
  34.     public Text Idelta;
  35.  
  36.     private bool canCalculate;
  37.     public float timeToDescalculate;
  38.     private float currentTimeToDescalculate;
  39.  
  40.     void Start () {
  41.         canCalculate = false;
  42.     }
  43.    
  44.     void Update () {
  45.         Ix1.text = x1.ToString();
  46.         Ix2.text = x2.ToString();
  47.         Idelta.text = delta.ToString();
  48.         XYZ();
  49.         if (delta > 0)
  50.             squareDelta = Mathf.Sqrt(delta);
  51.         sqrDelta = Convert.ToInt32(squareDelta);
  52.         if (canCalculate) {
  53.             Delta();
  54.             Bhaskhara();
  55.         }
  56.  
  57.         if (canCalculate) {
  58.             currentTimeToDescalculate += Time.deltaTime;
  59.         }
  60.  
  61.         if(currentTimeToDescalculate > timeToDescalculate) {
  62.             currentTimeToDescalculate = 0.0f;
  63.             canCalculate = false;
  64.         }
  65.     }
  66.  
  67.     void XYZ() {
  68.         Sx = Ix.text;
  69.         x = Convert.ToInt32(Sx);
  70.  
  71.         Sy = Iy.text;
  72.         y = Convert.ToInt32(Sy);
  73.  
  74.         Sz = Iz.text;
  75.         z = Convert.ToInt32(Sz);
  76.     }
  77.  
  78.     void Delta() {
  79.         delta = (x * x) - (4 * y * z);
  80.         Idelta.text = delta.ToString();
  81.     }
  82.  
  83.     void Bhaskhara() {
  84.         x1 = ((y * -1) + sqrDelta) / (2 * x);
  85.         x2 = ((y * -1) - sqrDelta) / (2 * x);
  86.     }
  87.  
  88.     public void Calculate() {
  89.         canCalculate = true;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment