Newer
Older
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class BlockObjectClass : MonoBehaviour
{
public float InhalePeriod { get; private set; }
public float ExhalePeriod { get; private set; }
public float MaxRuntime { get; private set; }
public AudioSource InhaleAudio;
public AudioSource ExhaleAudio;
TMP_InputField inhalePeriodTextInput;
TMP_InputField exhalePeriodTextInput;
TMP_InputField runtimeTextInput;
void Awake()
{
string name;
GameObject go;
Transform[] transforms = this.GetComponentsInChildren<Transform>();
foreach (var transform in transforms)
{
go = transform.gameObject;
name = go.name;
if (name == "Inhale")
{
inhalePeriodTextInput = go.GetComponent<TMP_InputField>();
SetInhalePeriod();
}
else if (name == "Exhale")
{
exhalePeriodTextInput = go.GetComponent<TMP_InputField>();
SetExhalePeriod();
}
else if (name == "Runtime")
{
SetRuntime();
}
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
if (inhalePeriod == -1)
{
InhalePeriod = (float)Convert.ToDouble(inhalePeriodTextInput.text);
}
else
{
InhalePeriod = inhalePeriod;
inhalePeriodTextInput.text = inhalePeriod.ToString();
AudioClip clip = Resources.Load(inhale_file) as AudioClip;
InhaleAudio.clip = clip;
if (exhalePeriod == -1)
{
ExhalePeriod = (float)Convert.ToDouble(exhalePeriodTextInput.text);
}
else
{
ExhalePeriod = exhalePeriod;
exhalePeriodTextInput.text = exhalePeriod.ToString();
float period = (float)Math.Round(exhalePeriod, 2);
String exhale_file = "exhale_" + period.ToString("0.0");
AudioClip clip = Resources.Load(exhale_file) as AudioClip;
ExhaleAudio.clip = clip;
if (runtimeInput == -1)
{
MaxRuntime = (float)Convert.ToDouble(runtimeTextInput.text) * 60;
}
else
{
MaxRuntime = runtimeInput;
runtimeTextInput.text = runtimeInput.ToString();