美文网首页
卡片收集2

卡片收集2

作者: 荼蘼toome | 来源:发表于2022-07-01 17:42 被阅读0次
image.png
image.png
image.png
image.png
image.png

卡片脚本:KaPian.cs

using UnityEngine;
using UnityEngine.UI;

public class KaPian : MonoBehaviour
{
    public int SceneIndex;
    public AudioClip clip;
    private Button btnCloseAudio;
    private bool IsClickImage = true;//只能点击一次卡片

    private void Start()
    {
        transform.GetChild(2).GetComponent<Button>().onClick.AddListener(CloseAudio);
    }

    public void OnClickImage()
    {
        if (!IsClickImage) return;
        IsClickImage = false;

        if (SceneIndex == 13)
        {
           Debug.Log("播放卡片声音:" + (WaSiTuChu.Instance.KaPianNum + 1));
            transform.GetChild(1).gameObject.SetActive(true);//显示收集图片
            WaSiTuChu.Instance.AudioSourceTip.clip = clip;
            WaSiTuChu.Instance.AudioSourceTip.Play();
            WaSiTuChu.Instance.KaPianNum++;
            Debug.Log("卡片数量"+WaSiTuChu.Instance.KaPianNum);
        }
        // if (SceneIndex == 8)
        // {
        //     print("播放卡片声音:" + (GongZiGangShangRen.Instance.KaPianNum + 1));
        //     transform.GetChild(1).gameObject.SetActive(true);
        //     GongZiGangShangRen.Instance.AudioSourceTip.clip = clip;
        //     GongZiGangShangRen.Instance.AudioSourceTip.Play();
        //     GongZiGangShangRen.Instance.KaPianNum++;
        // }
        else if (SceneIndex == 9)
        {
            print("播放卡片声音:" + (PianBangShangRen.Instance.KaPianNum + 1));
            transform.GetChild(1).gameObject.SetActive(true);
            PianBangShangRen.Instance.AudioSourceTip.clip = clip;
            PianBangShangRen.Instance.AudioSourceTip.Play();
            PianBangShangRen.Instance.KaPianNum++;
            Debug.Log("卡片数量" + PianBangShangRen.Instance.KaPianNum);
        }
        else if (SceneIndex == 6)
        {
            print("播放卡片声音:" + (MaoDingZaRen.Instance.KaPianNum + 1));
            transform.GetChild(1).gameObject.SetActive(true);
            MaoDingZaRen.Instance.AudioSourceTip.clip = clip;
            MaoDingZaRen.Instance.AudioSourceTip.Play();
            MaoDingZaRen.Instance.KaPianNum++;
        }
        if (SceneIndex == 1)
        {
            print("播放卡片声音:" + (KuaPengCtrl.Instance.IndexCard + 1));
            transform.GetChild(1).gameObject.SetActive(true);
            KuaPengCtrl.Instance.AudioSourceCard.clip = clip;
            KuaPengCtrl.Instance.AudioSourceCard.Play();
            KuaPengCtrl.Instance.IndexCard++;
            if (KuaPengCtrl.Instance.IndexCard==4&& !KuaPengCtrl.Instance.AudioSourceCard.isPlaying)//他的直接原因显示完全
            {  }
        }

        if (SceneIndex == 2)
        {
            print("播放卡片声音:" + (WeiZhangChengChe.Instance._Index + 1));
            transform.GetChild(1).gameObject.SetActive(true);
            WeiZhangChengChe.Instance.AudioSourceCard.clip = clip;
            WeiZhangChengChe.Instance.AudioSourceCard.Play();
            WeiZhangChengChe.Instance._Index++;
        }


        if (SceneIndex == 3)
        {
            print("播放卡片声音:" + (M_GunTonga.instance.index + 1));
            transform.GetChild(1).gameObject.SetActive(true);
            M_GunTonga.instance.audioSource.clip = clip;
            M_GunTonga.instance.audioSource.Play();
            M_GunTonga.instance.index++;
        }
        
    }
    public void CloseAudio()
    {
        if (SceneIndex == 13)
        {
            if (WaSiTuChu.Instance.AudioSourceTip.isPlaying)
                WaSiTuChu.Instance.AudioSourceTip.Stop();
        }
        // else if (SceneIndex == 8)
        // {
        //     if (GongZiGangShangRen.Instance.AudioSourceTip.isPlaying)
        //         GongZiGangShangRen.Instance.AudioSourceTip.Stop();
        // }
        else if (SceneIndex == 9)
        {
            if (PianBangShangRen.Instance.AudioSourceTip.isPlaying)
                PianBangShangRen.Instance.AudioSourceTip.Stop();
            if (PianBangShangRen.Instance.KaPianNum==6)
            {
                PianBangShangRen.Instance.KaPian.SetActive(false);
                PianBangShangRen.Instance.ChongDongE.SetActive(true);
                PianBangShangRen.Instance.AudioSourceBg.clip = PianBangShangRen.Instance.BgClips[1];
                PianBangShangRen.Instance.AudioSourceBg.Play();
                PianBangShangRen.Instance.AudioSourceTip.clip = PianBangShangRen.Instance.TipClips[3];
                PianBangShangRen.Instance.AudioSourceTip.Play();
            }

        }
        else if (SceneIndex == 6)
        {
            if (MaoDingZaRen.Instance.AudioSourceTip.isPlaying)
                MaoDingZaRen.Instance.AudioSourceTip.Stop();
        }
        else if (SceneIndex == 1)
        {
            if (KuaPengCtrl.Instance.AudioSourceCard.isPlaying)
                KuaPengCtrl.Instance.AudioSourceCard.Stop();
        }
        else if (SceneIndex == 2)
        {
            if (WeiZhangChengChe.Instance.AudioSourceCard.isPlaying)
                WeiZhangChengChe.Instance.AudioSourceCard.Stop();
        }
        else if (SceneIndex==3)
        {
            if (M_GunTonga.instance.audioSource.isPlaying)
                M_GunTonga.instance.audioSource.Stop();
        }
    }
}
using Pvr_UnitySDKAPI;
using System.Collections;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.UI;

public class MaoDingZaRen : GameManager
{
    /// <summary>
    /// 单列模式
    /// </summary>
    public static MaoDingZaRen Instance;
    [Header("主角")]
    public GameObject ART;
    public Transform player;
    [Header("卡片")]
    public GameObject KaPian;
    [Header("-----------------")]
    [Header("特效")]
    #region 特效
    public GameObject ChongDongE;
    public GameObject ChuanYueE;
    #endregion
    [Header("提示播放器")]
    public AudioSource AudioSourceTip;//提示文字播放器
    [Header("提示音")]
    public AudioClip[] TipClips;//对话语音
                                //1.虫洞提示2.
    [Header("背景播放器")]
    public AudioSource AudioSourceBg;//背景音播放器
    [Header("背景音")]
    public AudioClip[] BgClips;//打字机声音

public int KaPianNum;
  

    PlayableDirector timeline0;
    public GameObject pidai;
    public GameObject pidai2;
    public GameObject pidai3;
    public AudioSource wztc;

    private GameObject Env;
    private GameObject Ani;
    private GameObject but;
    private GameObject dh;
    private GameObject exitUI;

    private bool isKa;
    /// <summary>
    /// 初始化
    /// </summary>
    void Init()
    {
        Instance = this;
        timeline0 = GameObject.Find("TimeLine01").GetComponent<PlayableDirector>();

        Env = GameObject.Find("ART");
        Ani = GameObject.Find("Animation");
        but = GameObject.Find("SceneCanvas").GetChild(0).gameObject ;
        dh = ART.GetChild(1).GetChild(13).GetChild(0).GetChild(0).gameObject;
        exitUI = player.GetChild(0).GetChild(0).gameObject;
    }
    private void Start()
    {
        Init();
    }
    
    // Update is called once per frame
    void Update()
    {
        if (exitUI.activeSelf == false && (Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TRIGGER) || Input.GetKeyDown(KeyCode.Space) 
                                           || Input.GetButtonUp("Fire1") || Input.GetKeyDown(KeyCode.JoystickButton0)))
        {
            if (timeline0.time>10 && timeline0.time<90)
            {
                timeline0.time = 90;
            }else if (timeline0.time>95 && timeline0.time<220)
            {
                timeline0.time = 221;
            }
        }

        if (!isKa)
        {
            if (KaPian.activeSelf)
            {
                isKa = true;
                timeline0.Pause();
                StartCoroutine(Kapian());
            }   
        }
    }
   
    IEnumerator Kapian() 
    {
         player.position = new Vector3(0.5f, 1f, -14);
         player.eulerAngles = new Vector3(0, 0f, 0);
        // yield return new WaitForSeconds(1);
        // HeiPing.SetActive(false);
        while (KaPianNum != 6 || AudioSourceTip.isPlaying)//等待卡片收集完毕
        {
           print("当前卡片" + KaPianNum);
            yield return new WaitForSeconds(1);
        }
        KaPian.SetActive(false);
        Debug.LogError("虫洞");
        ChongDongE.SetActive(true);
        AudioSourceBg.clip = BgClips[1];
        AudioSourceBg.Play();
        AudioSourceTip.clip = TipClips[3];
        AudioSourceTip.Play();
    }
    /// <summary>
    /// 移动到虫洞及移动结束结束后剧情
    /// </summary>
    /// <returns></returns>
    IEnumerator ChongDongEnd()
    {
        bool move = true;
        while (move)
        {
            yield return new WaitForFixedUpdate();
            player.LookAt(ChongDongE.transform);
            player.Translate(Vector3.forward * Time.deltaTime * 1);
            if (Vector3.Distance(player.position, ChongDongE.transform.position) < 0.2f)
            {
                AudioSourceBg.Stop();
                move = false;
                ChongDongE.SetActive(false);
                RenderSettings.fog = false;
                ART.SetActive(false);
                ChuanYueE.SetActive(true);
                //隐藏人物
                Ani.SetActive(false);
                Env.SetActive(false);
                AudioSourceBg.clip = BgClips[2];
                AudioSourceBg.loop = true;
                AudioSourceBg.Play();
                yield return new WaitForSeconds(10);
                ChuanYueE.SetActive(false);
                RenderSettings.fog = true;
                ART.SetActive(true);
                AudioSourceBg.Stop();

                timeline0.time = 225.3f;
                timeline0.Play();
                //显示
                Ani.SetActive(true);
                Env.SetActive(true);
            }
        }
    }
    public override void RayButton(Transform t)
    {
        if (t.GetComponent<Button>())
            t.GetComponent<Button_VR>().RayEnter();
        if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TOUCHPAD) || 
            Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Space) || Input.GetButtonUp("Fire1") || Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            t.GetComponent<Button>().onClick.Invoke();
        }
    }
    public override void RayImage(Transform t)
    {
        if (t.GetComponent<Image>())
            t.GetComponent<Image>().color = Color.yellow;
        if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TOUCHPAD) || 
            Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Space) || Input.GetButtonUp("Fire1") || Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            if (t.parent.name == "KaPian")
            {
                print("按下了KaPian");
                t.GetComponent<KaPian>().OnClickImage();
                t.GetComponent<Collider>().enabled = false;
            }
        }
    }
    public override  void RayGo(Transform t)
    {
        if (t.GetComponent<MeshRenderer>())
            t.GetComponent<MeshRenderer>().material.color = Color.white;
        if (Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyDown(0, Pvr_KeyCode.TOUCHPAD) || 
            Controller.UPvr_GetKeyDown(1, Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Space) || Input.GetButtonUp("Fire1") || Input.GetKeyDown(KeyCode.JoystickButton0))
        {
            switch (t.name)
            {
                case "ChongDong":
                    print("按下了ChongDong。");
                    StartCoroutine(ChongDongEnd());
                    AudioSourceTip.Stop();
                    break;
            }
        }
    }

    public override  void RayButtonUp(Transform t)
    {
        if (t.GetComponent<Button>())
            t.GetComponent<Button_VR>().RayExit();
    }
    public override void RayImageUp(Transform t)
    {
        if (t.GetComponent<Image>())
            t.GetComponent<Image>().color = Color.white;
    }
 }

相关文章

  • 卡片收集2

    卡片脚本:KaPian.cs

  • 我的乐趣

    我的乐趣是收集奥特曼卡片,班上的同学也喜欢这种卡片,今天我就给你讲讲我收集的卡片吧。 刚翻开我的卡册,你可能觉得没...

  • 2018-01-26

    凯叔小知识卡片收集录

  • 2 如何使用卡片笔记

    根据文中作者所提到的,主要分为2类:1-文献卡片盒:文献和文献内容的简要说明2-主卡片盒:针对所阅读的内容收集和产...

  • iOS动画效果合集、飞吧企鹅游戏、换肤方案、画板、文字效果等源码

    iOS精选源码 动画知识运用及常见动画效果收集 3D卡片拖拽卡片叠加卡片 iFIERO - FLYING PENG...

  • 墨岚一周年活动

    1.感恩回馈卡片 收集现有的每位入住墨岚艺宿的客人姓名 送于感恩卡片和现金券(现金券额度再议面额小) 2.共众链接...

  • 创意的生成

    1.素材的积累 收集 卡片式收集 特殊素材和一般素材 彻底了解“产品与消费者的关系” 2.思维吸收 分门别类 ...

  • 痴迷于卡片收集

    文|小李非刀自从知道神书《卡片笔记写作法》,让我一发不可收拾,一直沉迷于卡片的收集和整理中。 从知道知识卡片这个概...

  • 水浒传武功排行榜

    小时候吃过一款干脆面,里面偶尔会附赠一些小卡片,小玩具。孩子心性,常常会把这些卡片收集起来,而曾经收集过的《水浒传...

  • 多子女养育:我有你不能有,你不能有我有的

    昨天姐姐买了一个收集叶罗丽卡片的册子,弟弟买了一个收集奥特曼卡片的册子。回家后姐姐找到了好几个美术机构的积分币,因...

网友评论

      本文标题:卡片收集2

      本文链接:https://www.haomeiwen.com/subject/itgcbrtx.html