找回密码
 立即注册
查看: 238|回复: 1

Unity笔记-做个狗里奥Demo给男票玩

[复制链接]
发表于 2022-10-1 16:06 | 显示全部楼层 |阅读模式
背景

因为平时确实很少需要打开,我每次打开Unity都是算是阔别重逢了,再加上工作本身的变动情况,整个人就是处于摆又摆不烂,卷又卷不赢,躺又躺不平,以至于那碗夹生的饭我咽了又咽的状态。
毕竟游戏是带给人快乐的,这也是我想要进入游戏行业的主要原因,对于游戏本身的热爱会让我在业余时间除了打游戏也会尝试做一做Demo,大概就是玩多了想做,做不下去了继续玩的状态,做Demo就是自我解救的一个过程,当我一次次和游戏同好讨论游戏想法、克服对于未知的恐惧解决了一个又一个BUG之后我会变得自信



在家玩游戏,又没有抽到甘雨妹妹

周末也会把Demo给男票京儿玩一玩,虽然Demo本身恶心但是最后他还是通关了,但是整个过程还是收获到了不少快乐



终于通关的纪念(时间还是有bug,实际不可能这么短

梦想就是一件非常想干的事情,然而这件事哪怕最后不能给你带来生活上极大的富足,但是我就是觉得我想成为这样的人。
说来惭愧因为公司搬得比较远,空闲时间比较少,所以Demo实在是拿不出手,但是还是做一个阶段性的总结吧。
思路

利用机制+马里奥的资源,机制用Unity的Prefab来制作,不同的机制写在枚举里,切换枚举对应不同的表现,做一个难以通关的狗里奥Demo版本。



机制拆解

Demo展示




狗里奥Demo简短展示
https://www.zhihu.com/video/1557095778040090624
机制

问号砖块

思路是利用马里奥砖块本身的属性,只是蘑菇经过了自己修图之后,变成了毒蘑菇,子弹花加了一个滤镜之后也变成了“霸王花”。
砖块类别作用
蘑菇吃了不再变大,而是直接中毒挂掉
子弹花触碰就挂
隐藏砖块只有当碰到的时候才会出现,用来封走位
普通砖块只是加金币,没什么实际作用
星星一碰出现好多星星,碰到就挂



砖块Prefab

绿水管

虽然很想用绿水管做类似隐藏通道的效果,但是因为不知道怎么做(真诚,有知道的也可以直接告诉我...)而作罢,思路就是枚举绿水管的机制,对于不同的机制控制不同子物体的Show/Hide。
绿水管作用
尖刺1玩家到绿水管的区域,就会出现,碰到就挂
尖刺2玩家到绿水管的区域,就会出现,碰到就挂,触碰范围比尖刺1大,算是进阶版本吧
动态尖刺虽然还是碰到就挂,但是尖刺本身是运动的
半物理水管上面过不过去,只能下面过去(京儿以为又是bug卡关,然而臣妾冤枉啊



绿水管Prefab

砖块

重力砖块,实现也很简单,走上去加刚体,并且设置刚体的重力为True。



重力砖块

软泥怪

玩家接近一定的水平距离,就会从天而降,前期必杀招。



软泥怪

总之,当这么多搞人心态的机制结合在了一起,就组成了狗里奥的关卡。



打不过去只能对着屏幕哔哔赖赖

核心代码

玩家

using UnityEngine;
using System.Collections;


public class PlayerController : MonoBehaviour {

        public float moveSpeed;
        public float additionalSpeedOnRun;

        public SpriteRenderer PlayerGrowShrinkRenderer;
        public SpriteRenderer TransformToFireMarioRenderer;

        private float activeMoveSpeed;
        private float currentAdditionalSpeedOnRun;

        public float additionalJumpSpeed;
        private float currentAdditionalJumpSpeed;

        public bool canMove;

        [HideInInspector]
        public Rigidbody2D myRigidbody;

        public float jumpSpeed;

        public Transform groundCheck;
        public float groundCheckRadius;
        public LayerMask whatIsGround;

        public bool isGrounded;

        bool PauseControl = false;

        private Animator myAnim;
        private SpriteRenderer mySpriteRenderer;

        public Vector3 respawnPosition;

        private LevelManager theLevelManager;

        public GameObject stompBox;

        public float knockBackForce;
        public float knockBackLength;
        private float knockBackCounter;

        public float invincibilityLength;
        private float invincibilityCounter;

        public AudioSource JumpAudioSource;
        public AudioSource PowerupAudioSource;

        public GameObject PlayerDies;

        private bool onPlatform;
        public float onPlatformSpeedModifier;

        BoxCollider2D BoxCollider;
        CircleCollider2D CircleCollider;

        Vector2 saveVelocity = new Vector2 ();
        //Vector2 saveAngularVelocity = new Vector2 ();

        public static bool PauseAllAnimations = false;

        public enum PlayerStates
        {
                Small, Big, BigFire
        };

        public static PlayerStates PlayerState;

        // Use this for initialization
        void Start () {
                myRigidbody = GetComponent<Rigidbody2D> ();
                myAnim = GetComponent<Animator> ();
                mySpriteRenderer = GetComponent<SpriteRenderer> ();

                canMove = true;
                if (Global.mData.isArchive)
                {
                        //只有一个存档点所以写死
                        respawnPosition = new Vector3(30.3899994F, -3.47000003F, 0);
                }
                else
                {
                        respawnPosition = transform.position;
                }

                transform.position = respawnPosition;
                theLevelManager = FindObjectOfType<LevelManager> ();

                BoxCollider = GetComponent<BoxCollider2D> ();
                CircleCollider = GetComponent<CircleCollider2D> ();

                activeMoveSpeed = moveSpeed;

                currentAdditionalSpeedOnRun = 0;
                currentAdditionalJumpSpeed = 0;

                PlayerState = PlayerStates.Small;

                TransformMarioToNewSize ();

                myAnim.Play("PlayerIdle");

                onPlatform = true;
        }

        public void TransformMarioToNewSize()
        {
                Vector2 v = new Vector2();

                switch (PlayerState)
                {
                        case PlayerStates.Small:
                                myAnim.Play("PlayerIdle");

                                v.x = 0;
                                v.y = 0.03f;

                                BoxCollider.offset = v;

                                v.x = 0.5f;
                                v.y = 0.59f;

                                BoxCollider.size = v;

                                v.x = 0;
                                v.y = -0.09f;

                                //CircleCollider.offset = v;

                                //CircleCollider.radius = 0.23f;
                                break;
                }
        }
        // Update is called once per frame
        void Update () {
                if (!PauseControl) {
                        isGrounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
                        if (knockBackCounter <= 0 && canMove) {
                                if (onPlatform) {
                                        activeMoveSpeed = (moveSpeed + currentAdditionalSpeedOnRun) * onPlatformSpeedModifier;
                                } else {
                                        activeMoveSpeed = moveSpeed + currentAdditionalSpeedOnRun;
                                }
                                if (Input.GetAxisRaw ("Horizontal") > 0f) {
                                        myRigidbody.velocity = new Vector3 (activeMoveSpeed, myRigidbody.velocity.y, 0f);
                                        mySpriteRenderer.flipX = false;
                                } else if (Input.GetAxisRaw ("Horizontal") < 0f) {
                                        myRigidbody.velocity = new Vector3 (-activeMoveSpeed, myRigidbody.velocity.y, 0f);
                                        mySpriteRenderer.flipX = true;
                                } else {
                                        myRigidbody.velocity = new Vector3 (0f, myRigidbody.velocity.y, 0f);
                                }
                                if (Input.GetKeyDown(KeyCode.Space) && isGrounded) {
                                        myRigidbody.velocity = new Vector3 (myRigidbody.velocity.x, jumpSpeed + currentAdditionalJumpSpeed, 0f);
                                                JumpAudioSource.Play ();
                                }
                                if (Input.GetKeyDown (KeyCode.B) && isGrounded) {
                                        Debug.Log ("Pressing on run buttton!");
                                        currentAdditionalSpeedOnRun = additionalSpeedOnRun;
                                        currentAdditionalJumpSpeed = additionalJumpSpeed;
                                }
                                if (Input.GetKeyDown(KeyCode.B)) {
                                        Debug.Log ("slow down!");
                                        currentAdditionalSpeedOnRun = 0;
                                        currentAdditionalJumpSpeed = 0;
                                }
                                //theLevelManager.invincible = false;
                        }

                        if (knockBackCounter > 0) {
                                knockBackCounter -= Time.deltaTime;

                                if (mySpriteRenderer.flipX)
                                        myRigidbody.velocity = new Vector3 (knockBackForce, knockBackForce / 2, 0f);
                                else
                                        myRigidbody.velocity = new Vector3 (-knockBackForce, knockBackForce / 2, 0f);
                        }

                        if (invincibilityCounter > 0) {
                                invincibilityCounter -= Time.deltaTime;

                        } else {
                                //theLevelManager.invincible = false;
                        }

                        myAnim.SetFloat ("Speed", Mathf.Abs (myRigidbody.velocity.x));
                        myAnim.SetBool ("Grounded", isGrounded);

                        if (myRigidbody.velocity.y < 0) {
                                stompBox.SetActive (true);

                        } else
                        {
                                stompBox.SetActive (false);
                               
                        }
                }
        }

        private void OnDrawGizmos()
        {
                Gizmos.color = Color.green;//改变线框的颜色
                Gizmos.DrawWireSphere(groundCheck.position, groundCheckRadius);//画圆
        }
        public void PlayerEnemyCollision() {
                Instantiate (PlayerDies, gameObject.transform.position, gameObject.transform.rotation);
                PauseAllAnimations = true;
                theLevelManager.levelMusic.Stop ();
                PauseControl = true;
                gameObject.SetActive (false);
       
        }

        public void PlayerDied()
        {

                Instantiate(PlayerDies, gameObject.transform.position, gameObject.transform.rotation);
                PauseAllAnimations = true;
                theLevelManager.levelMusic.Stop();
                PauseControl = true;
                gameObject.SetActive(false);
        }

        public void OnEnable() {
                knockBackCounter = 0;
        }

        void OnTriggerEnter2D(Collider2D other) {
                if (other.tag == "KillPlane") {

                        theLevelManager.HurtPlayer(1);

                }
                if (other.tag == "Checkpoint") {
                        respawnPosition = other.transform.position;
                }
                if (other.tag == "Mushroom"|| other.tag == "Flower"  ) {
                        Destroy (other.gameObject);

                        theLevelManager.HurtPlayer(1);
                }
                if (other.tag == "GravityBox")
                {
                        if (!other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                Rigidbody2D rb_box = other.gameObject.AddComponent<Rigidbody2D>();
                                rb_box.gravityScale = 1.0f;
                        }
                }
                // 软泥怪
                if (other.tag == "BadFlower")
                {
                        other.gameObject.SetActive(false);
                        theLevelManager.HurtPlayer(1);
                }
        }
        void PauseMarioWhileShrink() {
                PauseAllAnimations = true;
                PauseControl = true;
                saveVelocity = myRigidbody.velocity;
                //saveAngularVelocity = myRigidbody.angularVelocity;
                myRigidbody.velocity = Vector3.zero;
                myRigidbody.isKinematic = true;

                myAnim.Play ("ShrinkPlayer");
        }

        void OnCollisionEnter2D(Collision2D other) {
                if (other.gameObject.tag == "MovingPlatform") {
                        transform.parent = other.transform;
                        onPlatform = true;
                }

                if (other.gameObject.tag == "GravityBox")
                {
                        if (!other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                Rigidbody2D rb_box = other.gameObject.AddComponent<Rigidbody2D>();
                                rb_box.gravityScale = 1.0f;
                        }
                }

        }
        void OnCollisionExit2D(Collision2D other) {
                if (other.gameObject.tag == "MovingPlatform") {
                        transform.parent = null;
                        onPlatform = false;
                }
        }
}
问号砖块

using UnityEngine;
using System.Collections;

public class QuestionMark : MonoBehaviour {

        Animator theAnimator;
        /// <summary>
        /// JumpShowCoin:马里奥跳下去往上跳才显示,分成两种情况,从下往上,进入的时候显示,从上往下,离开的时候显示
        /// UnableCoin:马里奥碰到就显示
        ///  Coin:默认显示的金币
        ///  MushroomOrFlower:默认显示的蘑菇,大人就是显示花,花碰到就挂
        ///  Death:里面出来的鬼东西碰到就挂
        /// </summary>
        public enum Prize {JumpShowCoin, UnableCoin, Coin, MushroomOrFlower, Death}

        public Prize prize = Prize.Coin;

        private bool hitLeft = true;

        public GameObject mushroomPrefab;

        public GameObject flowerPrefab;

        public AudioSource PowerupAppearsAudioSource;

        public AudioSource BumpAudioSource;
        public AudioSource CoinAudioSource;

        private Transform bg;

        private LevelManager theLevelManager;

        // Use this for initialization
        void Start () {
                theAnimator = GetComponent<Animator> ();
                if (prize == Prize.UnableCoin|| prize == Prize.JumpShowCoin)
                {
                        bg= transform.Find("Block");
                        bg.gameObject.SetActive(false);
                }

                theLevelManager = FindObjectOfType<LevelManager>();
        }
       
        // Update is called once per frame
        void Update () {
               
        }

    private void OnTriggerExit2D(Collider2D other)
    {
                if (prize == Prize.JumpShowCoin && other.tag == "Player")
                {
                        if (GetComponent<BoxCollider2D>()&& other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                if (other.gameObject.GetComponent<Rigidbody2D>().velocity.y < 0 &&
                                        GetComponent<BoxCollider2D>().isTrigger == true)
                                {
                                        bg.gameObject.SetActive(true);
                                        GetComponent<BoxCollider2D>().isTrigger = false;


                                        theAnimator.SetTrigger("Hit");
                                        CoinAudioSource.Play();
                                        theLevelManager.AddCoin();
                                }

                        }
                }
        }
        void OnTriggerEnter2D(Collider2D other) {
                /// JumpShowCoin:马里奥跳下去往上跳才显示,分成两种情况,从下往上,进入的时候显示,从上往下,离开的时候显示
                /// UnableCoin:马里奥碰到就显示
                if (prize == Prize.UnableCoin&& other.tag == "Player")
                {
                        Debug.Log(other.gameObject.name);
                        bg.gameObject.SetActive(true);
                        theLevelManager.AddCoin();
                }
                if (prize == Prize.JumpShowCoin )
                {
                        if (GetComponent<BoxCollider2D>() && other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                  if (other.gameObject.GetComponent<Rigidbody2D>().velocity.y > 0&&
                                        GetComponent<BoxCollider2D>().isTrigger == true )
                                {
                                        bg.gameObject.SetActive(true);
                                        GetComponent<BoxCollider2D>().isTrigger = false;

                                        theAnimator.SetTrigger("Hit");
                                        CoinAudioSource.Play();
                                        theLevelManager.AddCoin();
                                }

                        }
                }

                if (other.tag == "Player") {
                        BumpAudioSource.Play ();
                }
                if (other.tag == "Player" && hitLeft) {
                        if (prize == Prize.Coin|| prize == Prize.UnableCoin ) {
                                theAnimator.SetTrigger ("Hit");
                                CoinAudioSource.Play ();
                                theLevelManager.AddCoin();
                        }
                        if (prize == Prize.MushroomOrFlower)
                        {
                                int i = Random.Range(0, 2);
                                if(i%2==0)
                                {
                                        theAnimator.SetTrigger("HitMushroom");
                                        PowerupAppearsAudioSource.Play();
                                }
                                else
                                {
                                        theAnimator.SetTrigger("HitFlower");
                                }

                        }
                        hitLeft = false;
                }
        }
        void OnMushroomAnimationEnd() {
                Transform mushTransform = GetComponent<Transform> ();

                GameObject mushroomInstance = (GameObject)Instantiate (mushroomPrefab, (mushTransform.position - new Vector3(0,-0.8f,0)), Quaternion.identity);
                mushroomInstance.GetComponent<Transform> ().parent = null;

        }
        void OnFlowerAnimationEnd() {
                Transform theTransform = GetComponent<Transform> ();

                GameObject flowerInstance = (GameObject)Instantiate (flowerPrefab, (theTransform.position - new Vector3(0,-0.74f,0)), Quaternion.identity);
                flowerInstance.GetComponent<Transform> ().parent = null;
        }
}
问号砖块

using UnityEngine;
using System.Collections;

public class QuestionMark : MonoBehaviour {

        Animator theAnimator;
        /// <summary>
        /// JumpShowCoin:马里奥跳下去往上跳才显示,分成两种情况,从下往上,进入的时候显示,从上往下,离开的时候显示
        /// UnableCoin:马里奥碰到就显示
        ///  Coin:默认显示的金币
        ///  MushroomOrFlower:默认显示的蘑菇,大人就是显示花,花碰到就挂
        ///  Death:里面出来的鬼东西碰到就挂
        /// </summary>
        public enum Prize {JumpShowCoin, UnableCoin, Coin, MushroomOrFlower, Death}

        public Prize prize = Prize.Coin;

        private bool hitLeft = true;

        public GameObject mushroomPrefab;

        public GameObject flowerPrefab;

        public AudioSource PowerupAppearsAudioSource;

        public AudioSource BumpAudioSource;
        public AudioSource CoinAudioSource;

        private Transform bg;

        private LevelManager theLevelManager;

        // Use this for initialization
        void Start () {
                theAnimator = GetComponent<Animator> ();
                if (prize == Prize.UnableCoin|| prize == Prize.JumpShowCoin)
                {
                        bg= transform.Find("Block");
                        bg.gameObject.SetActive(false);
                }

                theLevelManager = FindObjectOfType<LevelManager>();
        }
       
        // Update is called once per frame
        void Update () {
               
        }

    private void OnTriggerExit2D(Collider2D other)
    {
                if (prize == Prize.JumpShowCoin && other.tag == "Player")
                {
                        if (GetComponent<BoxCollider2D>()&& other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                if (other.gameObject.GetComponent<Rigidbody2D>().velocity.y < 0 &&
                                        GetComponent<BoxCollider2D>().isTrigger == true)
                                {
                                        bg.gameObject.SetActive(true);
                                        GetComponent<BoxCollider2D>().isTrigger = false;


                                        theAnimator.SetTrigger("Hit");
                                        CoinAudioSource.Play();
                                        theLevelManager.AddCoin();
                                }

                        }
                }
        }
        void OnTriggerEnter2D(Collider2D other) {
                /// JumpShowCoin:马里奥跳下去往上跳才显示,分成两种情况,从下往上,进入的时候显示,从上往下,离开的时候显示
                /// UnableCoin:马里奥碰到就显示
                if (prize == Prize.UnableCoin&& other.tag == "Player")
                {
                        Debug.Log(other.gameObject.name);
                        bg.gameObject.SetActive(true);
                        theLevelManager.AddCoin();
                }
                if (prize == Prize.JumpShowCoin )
                {
                        if (GetComponent<BoxCollider2D>() && other.gameObject.GetComponent<Rigidbody2D>())
                        {
                                  if (other.gameObject.GetComponent<Rigidbody2D>().velocity.y > 0&&
                                        GetComponent<BoxCollider2D>().isTrigger == true )
                                {
                                        bg.gameObject.SetActive(true);
                                        GetComponent<BoxCollider2D>().isTrigger = false;

                                        theAnimator.SetTrigger("Hit");
                                        CoinAudioSource.Play();
                                        theLevelManager.AddCoin();
                                }

                        }
                }

                if (other.tag == "Player") {
                        BumpAudioSource.Play ();
                }
                if (other.tag == "Player" && hitLeft) {
                        if (prize == Prize.Coin|| prize == Prize.UnableCoin ) {
                                theAnimator.SetTrigger ("Hit");
                                CoinAudioSource.Play ();
                                theLevelManager.AddCoin();
                        }
                        if (prize == Prize.MushroomOrFlower)
                        {
                                int i = Random.Range(0, 2);
                                if(i%2==0)
                                {
                                        theAnimator.SetTrigger("HitMushroom");
                                        PowerupAppearsAudioSource.Play();
                                }
                                else
                                {
                                        theAnimator.SetTrigger("HitFlower");
                                }

                        }
                        hitLeft = false;
                }
        }
        void OnMushroomAnimationEnd() {
                Transform mushTransform = GetComponent<Transform> ();

                GameObject mushroomInstance = (GameObject)Instantiate (mushroomPrefab, (mushTransform.position - new Vector3(0,-0.8f,0)), Quaternion.identity);
                mushroomInstance.GetComponent<Transform> ().parent = null;

        }
        void OnFlowerAnimationEnd() {
                Transform theTransform = GetComponent<Transform> ();

                GameObject flowerInstance = (GameObject)Instantiate (flowerPrefab, (theTransform.position - new Vector3(0,-0.74f,0)), Quaternion.identity);
                flowerInstance.GetComponent<Transform> ().parent = null;
        }
}
绿水管

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GreenTubeController : MonoBehaviour
{

    public enum Prize { None, Flower, StaticSpawn, DynamicSpawn}

    public Prize prize = Prize.None;
    // 动态炸弹出现的声音
    public AudioSource DynamicSpawnSound;

    // 静态炸弹出现的声音
    public AudioSource StaticSpawnSound;

    // 花花出现的声音
    public AudioSource FlowerSound;
    //是否已经踩过坑了
    private bool hitLeft = true;

    public GameObject flowerObj;

    public GameObject staticObj;

    public GameObject dynamicObj;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        // 只有当人物下方踩到才算是触发!!!写死
        Debug.Log(other.gameObject.name);
        if (other.gameObject.name == "StompBox")
        {
            if (hitLeft)
            {
                switch (prize)
                {
                    case Prize.Flower:
                        flowerObj.SetActive(true);
                        FlowerSound.Play();
                        break;
                    case Prize.StaticSpawn:

                        StartCoroutine(StaticSpawn());
                        StaticSpawnSound.Play();
                        break;

                    case Prize.DynamicSpawn:
                        dynamicObj.SetActive(true);
                        DynamicSpawnSound.Play();
                        break;

                }
                hitLeft = false;
            }
        }



     }


    public IEnumerator StaticSpawn()
    {

        yield return new WaitForSeconds(0.5f);
        staticObj.SetActive(true);

    }
}
管理类

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;


public class Global
{
        public static Global mData = new Global();

        public int maxHealth = 2;
        public bool isArchive = false;
        public int midTime = 0;
        public Global()
    {

    }
}
public class LevelManager : MonoBehaviour {

        public float waitToRespawn;
        public PlayerController thePlayer;
        public GameObject deathExplosion;
        public int coinCount;
        public int bonusLifeThreshold;

        public Text coinText;
        // 當前場景生命
        public int healthCount;

        private bool respawning;

        private ResetOnRespawn[] objectsToReset;

        public GameObject gameScreen;
        public Text deathText;
        public Text life;

        public GameObject endScreen;
        public Text endText;
        public Text endlife;

        public AudioSource levelMusic;

        public AudioSource coinAudioSource;

        private bool isMid=false;
        private int useTime;

        // Use this for initialization
        void Start () {
                thePlayer = FindObjectOfType<PlayerController> ();
                // 当前血量
                healthCount = 1;

                gameScreen.SetActive(false);
                endScreen.SetActive(false);

                life.text = healthCount.ToString();

                objectsToReset = FindObjectsOfType<ResetOnRespawn> ();


                coinText.text = "00" /*+ coinCount*/;
                Invoke("AddTime", 1f);
        }
       
        // Update is called once per frame
        void Update () {
                // 当前场景生命
                if (healthCount <= 0&&!respawning) {
                        Respawn ();
                        respawning = true;
                }
                if (gameScreen.activeInHierarchy)
                {

                        if (Input.GetKeyDown(KeyCode.Y))
                        {
                                PlayerPrefs.SetInt("CoinCount", 0);
                                PlayerPrefs.SetInt("PlayerLives", Global.mData.maxHealth);
                                PlayerController.PauseAllAnimations = false;
                                SceneManager.LoadScene(SceneManager.GetActiveScene().name);
                        }
                        if (Input.GetKeyDown(KeyCode.N))
                        {

                                Application.Quit();
                        }

                }

        }

        public void ShowSuccess()
        {
                endScreen.SetActive(true);
                if (Global.mData.isArchive)
                {
                        useTime += Global.mData.midTime;
                }
                if (useTime > 60)
                {
                        int min = useTime / 60;
                        int s = useTime % 60;
                        if (min > 10)
                        {
                                endText.text = string.Format("{0}m{1}s才通关,太慢了叭!", min.ToString(), s.ToString());

                        }
                        else
                        {

                                endText.text = string.Format("太棒了,{0}m{1}s就通关啦!", min.ToString(), s.ToString());
                        }
                }
                else {
                        int s = useTime % 60;
                        endText.text = string.Format("有奖励哦,{0}s就通关啦!", s.ToString());
                }
                endlife.text = Global.mData.maxHealth.ToString();

        }

        void AddTime()
        {
                useTime++;
                Invoke("AddTime", 1f);
                if (Global.mData.isArchive == true && !isMid)
                {
                        Global.mData.midTime = useTime;
                        isMid = true;
                }
        }
        public void Respawn()
        {
                CancelInvoke("AddTime");
                Global.mData.maxHealth -= 1;
                StartCoroutine(RespawnCo());
                thePlayer.gameObject.SetActive (false);
               
                levelMusic.Stop ();
        }

        public void AddCoin()
        {
                coinCount += 200;
                coinText.text = coinCount.ToString();
        }

        public IEnumerator RespawnCo() {
                thePlayer.gameObject.SetActive (false);

                Instantiate (deathExplosion, thePlayer.transform.position, thePlayer.transform.rotation);

                yield return new WaitForSeconds (waitToRespawn);

                gameScreen.SetActive(true);
                if (useTime > 60)
                {
                        int min = useTime / 60;
                        int s = useTime % 60;

                        deathText.text = string.Format("仅仅用{0}m{1}s就寄了", min.ToString(), s.ToString());
                }
                else
                {
                        int s = useTime;
                        deathText.text = string.Format("仅仅用{0}s就寄了", s.ToString());
                }
                life.text = Global.mData.maxHealth.ToString();

                coinCount = 0;

                thePlayer.transform.position = thePlayer.respawnPosition;
                thePlayer.gameObject.SetActive (true);

                for (int i = 0; i < objectsToReset.Length; ++i) {               
                        objectsToReset .gameObject.SetActive (true);       
                        objectsToReset .ResetObject ();
                }
        }

        public void HurtPlayer(int damageToTake) {
                healthCount-= damageToTake;
                thePlayer.PlayerEnemyCollision ();
        }


}

未来计划

做个Boss关!



玩法示意

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2022-10-1 16:12 | 显示全部楼层
厉害了!
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-7-4 09:09 , Processed in 0.119304 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表