在项目中只用于写碰撞器等操作
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;
using UnityEngine.UI;
/*
*创建者:
*创建时间:
*描述:
*版本:
*/
public class PlayerTirgger : MonoBehaviour
{
private AudioSource audios;
private AudioClip clip, doorOpen,NoKeyDoor;//声音管理
private GameObject door,win;//第一关door门,win最后胜利的门
private GameObject gameOver;//游戏结束画面
private bool doorSetActive=false;//第一关门
private bool OpenDoor = true;//打开胜利的钥匙
private Text tap;
private GameObject[] player;
private float nextTime=0;
// Start is called before the first frame update
void Start()
{
audios= GetComponent<AudioSource>();
clip = Resources.Load<AudioClip>(GameResources.GetKeyCard);
doorOpen = Resources.Load<AudioClip>(GameResources.DoorOpen);
NoKeyDoor = Resources.Load<AudioClip>(GameResources.NoDoorOpen);
door = GameObject.FindWithTag("Door");
win = GameObject.FindWithTag("Win");
tap = GameObject.Find("GameOver").transform.GetChild(0).GetComponent<Text>();
}
// Update is called once per frame
void Update()
{
if (doorSetActive)//第一关门的落下显示
{
nextTime += Time.deltaTime;
if (nextTime>=3)
{
door.gameObject.SetActive(true);
nextTime = 0;
doorSetActive = false;
}
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("KeyCard"))
{
audios.clip = clip;
GameManager.Instance().keyCard = true;
audios.Play();
Destroy(collision.gameObject);
print(GameManager.Instance().keyCard);
}
if (collision.gameObject.CompareTag("Door") && GameManager.Instance().keyCard)//获取到Card并靠近门时,开门
{
collision.gameObject.SetActive(false);//挡住的门消失
audios.clip = doorOpen;
audios.Play();
doorSetActive = true;//开启倒计时,把门出现
}
else if (collision.gameObject.CompareTag("Door") && GameManager.Instance().keyCard == false)//没有获取到Card并靠近门时
{
audios.clip = NoKeyDoor;
if (!audios.isPlaying)//警报声响起
{
audios.Play();
}
GameManager.Instance().PlayerHp -= 1;//玩家持续扣血
}
else if (collision.gameObject.CompareTag("Door"))//其他的操作
{
}
if (collision.gameObject.CompareTag("WinCard"))
{
audios.clip = clip;
GameManager.Instance().WinCard = true;
audios.Play();
Destroy(collision.gameObject);
}
if (collision.gameObject.CompareTag("Win") && GameManager.Instance().WinCard&&GameManager.Instance().feng>=50)
{
tap.text = "恭喜你游戏胜利!!!";
GetComponent<MouseLook>().enabled = false;
if (GameObject.Find("Player1")!=null)
{
GetComponent<PlayerACR>().enabled = false;
}
if (GameObject.Find("G36C@Draw")!=null)
{
GetComponent<PlayerTwoG36C>().enabled = false;
}
Time.timeScale = 0;
}
else if (collision.gameObject.CompareTag("Win") && GameManager.Instance().WinCard == false)
{
tap.text = "请获取钥匙再开门";
Invoke("tapTxt", 3f);
}
else if (collision.gameObject.CompareTag("Win") && GameManager.Instance().WinCard == true&& GameManager.Instance().feng < 50)
{
tap.text = "请累积积分至50分";
Invoke("tapTxt", 3f);
}
else if (collision.gameObject.CompareTag("Win"))//其他的操作
{
}
}
void tapTxt()
{
tap.text = "";
}
}