Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class VoltageControl : MonoBehaviour {
  7.     public GameObject scoreText; //shows the voltage
  8.  
  9.     public GameObject NegPoint; //negative part of battery
  10.     public GameObject PosPoint; //positive part of battery
  11.  
  12.     private  ChargeNum posScript; //script for the posiitve connection of the battery that detects if it touched the voltmeter
  13.     private ChargeNum2 negScript; //script for the negative connection of the battery that detects if it touched the voltmeter
  14.  
  15.  
  16.     public int charge = 0;
  17.     // Use this for initialization
  18.     void Start () {
  19.         posScript = PosPoint.GetComponent<ChargeNum>(); //get the script
  20.         negScript = NegPoint.GetComponent<ChargeNum2>();//get the script
  21.  
  22.         scoreText.GetComponent<Text>().text = "Charge" + charge; //setup the text for the voltage
  23.     }
  24.    
  25.     // Update is called once per frame
  26.     void Update () {
  27.         if(negScript.linked==true && posScript.linked == true) //if both connections are made
  28.         {
  29.             charge += 5;//increase charge by 5
  30.             scoreText.GetComponent<Text>().text = "Charge" + charge;//get the script
  31.         }
  32.  
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement