2021-09-07 22:20:19 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class GunLight : MonoBehaviour
|
|
|
|
{
|
|
|
|
private bool upLight = true;
|
2021-09-09 00:59:27 +08:00
|
|
|
public GameObject light1;
|
|
|
|
//public GameObject light2;
|
|
|
|
|
|
|
|
public bool isFire = false;
|
|
|
|
|
|
|
|
public bool isInvoke = false;
|
2021-09-07 22:20:19 +08:00
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
InvokeRepeating("ChangeLight",1f,0.05f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
2021-09-09 00:59:27 +08:00
|
|
|
if (isFire && (!isInvoke))
|
|
|
|
{
|
|
|
|
InvokeRepeating("ChangeLight",0f,0.05f);
|
|
|
|
isInvoke = true;
|
|
|
|
}
|
2021-09-07 22:20:19 +08:00
|
|
|
|
2021-09-09 00:59:27 +08:00
|
|
|
if (!isFire && isInvoke)
|
|
|
|
{
|
|
|
|
CancelInvoke();
|
|
|
|
isInvoke = false;
|
|
|
|
light1.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 22:20:19 +08:00
|
|
|
void ChangeLight()
|
|
|
|
{
|
|
|
|
if (upLight)
|
|
|
|
{
|
2021-09-09 00:59:27 +08:00
|
|
|
light1.SetActive(upLight);
|
|
|
|
// light2.SetActive(upLight);
|
2021-09-07 22:20:19 +08:00
|
|
|
upLight = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2021-09-09 00:59:27 +08:00
|
|
|
// light2.SetActive(upLight);
|
|
|
|
light1.SetActive(upLight);
|
2021-09-07 22:20:19 +08:00
|
|
|
upLight = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|