Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Bhaskara : MonoBehaviour {
- [Header("X")]
- public int x;
- private string Sx;
- public Text Ix;
- [Header("Y")]
- public int y;
- private string Sy;
- public Text Iy;
- [Header("Z")]
- public int z;
- private string Sz;
- public Text Iz;
- [Header("Result")]
- public int x1;
- public Text Ix1;
- public int x2;
- public Text Ix2;
- public int delta;
- public float squareDelta;
- public int sqrDelta;
- public Text Idelta;
- private bool canCalculate;
- public float timeToDescalculate;
- private float currentTimeToDescalculate;
- void Start () {
- canCalculate = false;
- }
- void Update () {
- Ix1.text = x1.ToString();
- Ix2.text = x2.ToString();
- Idelta.text = delta.ToString();
- XYZ();
- if (delta > 0)
- squareDelta = Mathf.Sqrt(delta);
- sqrDelta = Convert.ToInt32(squareDelta);
- if (canCalculate) {
- Delta();
- Bhaskhara();
- }
- if (canCalculate) {
- currentTimeToDescalculate += Time.deltaTime;
- }
- if(currentTimeToDescalculate > timeToDescalculate) {
- currentTimeToDescalculate = 0.0f;
- canCalculate = false;
- }
- }
- void XYZ() {
- Sx = Ix.text;
- x = Convert.ToInt32(Sx);
- Sy = Iy.text;
- y = Convert.ToInt32(Sy);
- Sz = Iz.text;
- z = Convert.ToInt32(Sz);
- }
- void Delta() {
- delta = (x * x) - (4 * y * z);
- Idelta.text = delta.ToString();
- }
- void Bhaskhara() {
- x1 = ((y * -1) + sqrDelta) / (2 * x);
- x2 = ((y * -1) - sqrDelta) / (2 * x);
- }
- public void Calculate() {
- canCalculate = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment