using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class button : MonoBehaviour
{
public Button btn;
private int a;
private float now_time;
public GameObject circle;
public GameObject fraction1;
public GameObject fraction2;
public GameObject fraction3;
// Start is called before the first frame update
void Start()
{
fraction1.SetActive(false);
fraction2.SetActive(false);
fraction3.SetActive(false);
btn.onClick.AddListener(() => { OnClickBtn(btn.gameObject); });
}
// Update is called once per frame
void Update()
{
now_time += Time.deltaTime;
Destroy(gameObject, 2.8f);
Destroy(circle.gameObject, 2.8f);
}
public void OnClickBtn(GameObject Button)
{
Destroy(gameObject);
Destroy(circle.gameObject);
Debug.Log("按钮被点击");
if (now_time < 1.0f)
{
fraction1.SetActive(true);
Destroy(fraction1.gameObject, 0.3f);
}
if (now_time > 2.0f)
{
fraction3.SetActive(true);
Destroy(fraction3.gameObject, 0.3f);
}
else if(1<now_time&& now_time < 2)
{
fraction2.SetActive(true);
Destroy(fraction2.gameObject, 0.3f);
}
}
}
下面代码是当超过一定的时间后不按下按钮会显示的图片以及点击后的总分计算
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class game : button
{
private float now_time1;
public int a1;
public int b;
public GameObject fraction;
public GameObject Tscore;
public GameObject g;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
now_time1 += Time.deltaTime;
a1 = (int)now_time1;
if (now_time1 <= 2.9999f)
{
a1 = (a1 + 1) * 100;
}
else if (now_time1 > 3.15f)
{
if (fraction1 != null)
{
if(fraction2 != null)
{
if (fraction3 != null)
{
if (fraction != null)
{
fraction.SetActive(true);
Destroy(fraction.gameObject, 0.3f);
}
}
}
}
a1 = 0;
}
Destroy(g.gameObject, 3.5f);
}
public void scoreText()
{
b = +a1;
Tscore.gameObject.GetComponent<Text>().text = b.ToString();
}
}