Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Vuforia;
- public class WeldingOnOff : MonoBehaviour {
- // Initialize Welding Button
- public Button WeldingBtn;
- // Initialize Spark Object
- public GameObject Spark;
- public AudioSource SparkSound;
- // Initialize Fire Object
- public GameObject Fire;
- public Text Guide;
- public AudioSource Selesai;
- // Mode
- //public GameObject TwoF;
- //public GameObject TwoG;
- //public string mode;
- // Initialize Trigger
- public bool WeldingOn;
- // Setup range limit
- public float range = 1f;
- // Setup raycast hit
- RaycastHit hit;
- // Camera
- public Camera camera;
- void OnEnable()
- {
- // Register Button Events
- WeldingBtn.onClick.AddListener(() => buttonCallBack(WeldingBtn));
- }
- private void buttonCallBack(Button buttonPressed)
- {
- if (buttonPressed == WeldingBtn)
- {
- WeldingOn = !WeldingOn;
- }
- }
- void OnDisable()
- {
- // Un-Register Button Events
- WeldingBtn.onClick.RemoveAllListeners();
- }
- // Start is called before the first frame update
- void Start()
- {
- Spark.SetActive(false);
- Fire.SetActive(false);
- }
- // Update is called once per frame
- void Update()
- {
- if (WeldingOn)
- {
- Fire.SetActive(true);
- // Get the Vuforia StateManager
- StateManager sm = TrackerManager.Instance.GetStateManager();
- // Query the StateManager to retrieve the list of
- // currently 'active' trackables
- //(i.e. the ones currently being tracked by Vuforia)
- IEnumerable<TrackableBehaviour> activeTrackables = sm.GetActiveTrackableBehaviours();
- foreach (TrackableBehaviour tb in activeTrackables)
- {
- var jarak = Vector3.Distance(camera.transform.position, tb.gameObject.transform.position);
- Debug.Log("Jarak:" + jarak);
- Debug.Log("X:" + (camera.transform.position.x - tb.gameObject.transform.position.x));
- Debug.Log("Y:" + (camera.transform.position.y - tb.gameObject.transform.position.y));
- Debug.Log("Z:" + (camera.transform.position.z - tb.gameObject.transform.position.z));
- if (tb.name == "Marker2F")
- {
- //detek jarak 2f
- if (jarak <= 450)
- {
- Spark.SetActive(true);
- SparkSound.Play();
- }
- else if (jarak >= 450)
- {
- Spark.SetActive(false);
- SparkSound.Stop();
- Guide.text = "Pengelasan 2F Selesai";
- Selesai.Play();
- Selesai.Stop();
- }
- else
- {
- Spark.SetActive(false);
- SparkSound.Stop();
- }
- }
- if(tb.name == "Marker2G")
- {
- //detek jarak 2g
- if ((jarak >= 192) && (jarak <= 270))
- {
- Spark.SetActive(true);
- SparkSound.Play();
- }
- else if (jarak >= 270)
- {
- Spark.SetActive(false);
- SparkSound.Stop();
- Guide.text = "Pengelasan 2G Selesai";
- Selesai.Play();
- Selesai.Stop();
- }
- else
- {
- Spark.SetActive(false);
- SparkSound.Stop();
- }
- }
- }
- }
- else
- {
- Spark.SetActive(false);
- Fire.SetActive(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement