最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Unity實現(xiàn)見縫插針小游戲

 更新時間:2020年04月16日 17:05:51   作者:菠蘿小笨笨  
這篇文章主要為大家詳細介紹了Unity實現(xiàn)見縫插針小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Unity實現(xiàn)見縫插針游戲的具體代碼,供大家參考,具體內(nèi)容如下

控制小球旋轉(zhuǎn)

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

public class RotateSelf : MonoBehaviour {
  //每秒旋轉(zhuǎn)90度
  public float speed = 90;

  // Update is called once per frame
  void Update () {
   //繞Z軸順針旋轉(zhuǎn)
    transform.Rotate(new Vector3(0, 0, -speed * Time.deltaTime));
  }
}

針頭碰撞檢測

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

public class PinHead : MonoBehaviour {

  private void OnTriggerEnter2D(Collider2D collision)
  {
    if (collision.tag == "PinHead")
    {
      GameObject.Find("GameManager").GetComponent<GameManager>().GameOver();
    }
  }
}

控制針的運動位置

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

public class Pin : MonoBehaviour {

  public float speed = 5;
  private bool isFly = false;
  private bool isReach = false;
  private Transform startPoint;
  private Vector3 targetCirclePos;
  private Transform circle;

  // Use this for initialization
  void Start () {
    startPoint = GameObject.Find("StartPoint").transform;
    circle = GameObject.FindGameObjectWithTag("Circle").transform;
    targetCirclePos = circle.position;
    targetCirclePos.y -= 1.55f;
  }

  // Update is called once per frame
  void Update () {
    if (isFly == false)
    {
      if (isReach == false)
      {
        transform.position = Vector3.MoveTowards(transform.position, startPoint.position, speed * Time.deltaTime);
        if (Vector3.Distance(transform.position, startPoint.position) < 0.05f)
        {
          isReach = true;
        }
      }
    }
    else
    {
      transform.position = Vector3.MoveTowards(transform.position, targetCirclePos, speed * Time.deltaTime);
      if(Vector3.Distance( transform.position,targetCirclePos) < 0.05f)
      {
        transform.position = targetCirclePos;
        transform.parent = circle;
        isFly = false;
      }
    }
  }

  public void StartFly()
  {
    isFly = true;
    isReach = true;
  }
}

游戲管理

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

public class GameManager : MonoBehaviour {

  private Transform startPoint;
  private Transform spawnPoint;
  private Pin currentPin;
  private bool isGameOver = false;
  private int score = 0;
  private Camera mainCamera;
  public Text scoreText;
  public GameObject pinPrefab;
  public float speed = 3;

  // Use this for initialization
  void Start () {
    startPoint = GameObject.Find("StartPoint").transform;
    spawnPoint = GameObject.Find("SpawnPoint").transform;
    mainCamera = Camera.main;
    SpawnPin();
  }

  private void Update()
  {
    if (isGameOver) return;
    if (Input.GetMouseButtonDown(0))
    {
      score++;
      scoreText.text = score.ToString();
      currentPin.StartFly();
      SpawnPin();
    }
  }

  void SpawnPin()
  {
     //針的實例化
    currentPin = GameObject.Instantiate(pinPrefab, spawnPoint.position, pinPrefab.transform.rotation).GetComponent<Pin>();
  }

  public void GameOver()
  {
    if (isGameOver) return;
    GameObject.Find("Circle").GetComponent<RotateSelf>().enabled = false;
    StartCoroutine(GameOverAnimation());
    isGameOver = true;
  }

  IEnumerator GameOverAnimation()
  {
    while (true)
    {
      mainCamera.backgroundColor = Color.Lerp(mainCamera.backgroundColor, Color.red, speed * Time.deltaTime);
      mainCamera.orthographicSize = Mathf.Lerp(mainCamera.orthographicSize, 4, speed * Time.deltaTime);
      if( Mathf.Abs( mainCamera.orthographicSize-4 )<0.01f)
      {
        break;
      }
      yield return 0;
    }
    yield return new WaitForSeconds(0.2f);
    //重新加載場景
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  }
}

游戲初始狀態(tài)和運行結(jié)果

更多有趣的經(jīng)典小游戲?qū)崿F(xiàn)專題,分享給大家:

C++經(jīng)典小游戲匯總

python經(jīng)典小游戲匯總

python俄羅斯方塊游戲集合

JavaScript經(jīng)典游戲 玩不停

java經(jīng)典小游戲匯總

javascript經(jīng)典小游戲匯總

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 深入多線程之:Reader與Write Locks(讀寫鎖)的使用詳解

    深入多線程之:Reader與Write Locks(讀寫鎖)的使用詳解

    本篇文章是對Reader與Write Locks(讀寫鎖)的使用進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C#中方法的直接調(diào)用、反射調(diào)用與Lambda表達式調(diào)用對比

    C#中方法的直接調(diào)用、反射調(diào)用與Lambda表達式調(diào)用對比

    這篇文章主要介紹了C#中方法的直接調(diào)用、反射調(diào)用與Lambda表達式調(diào)用對比,本文著重講解了方法的三種調(diào)用方法以及它們的性能對比,需要的朋友可以參考下
    2015-06-06
  • 在WPF中動態(tài)加載XAML中的控件實例代碼

    在WPF中動態(tài)加載XAML中的控件實例代碼

    這篇文章主要介紹了在WPF中動態(tài)加載XAML中的控件,實例分析了WPF中針對XAML中控件的動態(tài)調(diào)用技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-07-07
  • WPF實現(xiàn)帶篩選功能的DataGrid

    WPF實現(xiàn)帶篩選功能的DataGrid

    在默認情況下,WPF提供的DataGrid僅擁有數(shù)據(jù)展示等簡單功能,如果要實現(xiàn)像Excel一樣復(fù)雜的篩選過濾功能,則相對比較麻煩。本文以一個簡單的小例子,簡述如何通過WPF實現(xiàn)DataGrid的篩選功能,僅供學習分享使用,如有不足之處,還請指正
    2023-03-03
  • C# GetField方法的應(yīng)用實例講解

    C# GetField方法的應(yīng)用實例講解

    C#中的GetField是一個反射方法,用于獲取指定類型的字段信息,它可以通過字段名稱來獲取字段對象,并且可以在運行時動態(tài)地訪問和操作這些字段,本文給大家介紹了C# GetField方法的應(yīng)用,需要的朋友可以參考下
    2024-04-04
  • 詳解C#如何使用讀寫鎖控制多線程寫入

    詳解C#如何使用讀寫鎖控制多線程寫入

    這篇文章主要為大家詳細介紹了C#如何使用讀寫鎖控制多線程寫入,文中的示例代碼講解詳細,具有一定的借鑒價值,感興趣的小伙伴可以跟隨小編一起學習一下
    2024-01-01
  • 在 C# 中使用 Span<T> 和 Memory<T> 編寫高性能代碼的詳細步驟

    在 C# 中使用 Span<T> 和 Memory<

    在本文中,將會介紹 C# 7.2 中引入的新類型:Span 和 Memory,文章深入研究?Span<T>?和?Memory<T>?,并演示如何在 C# 中使用它們,需要的朋友可以參考下
    2022-08-08
  • C#編寫游戲客戶端的實現(xiàn)代碼

    C#編寫游戲客戶端的實現(xiàn)代碼

    這篇文章主要介紹了C#編寫游戲客戶端的實現(xiàn)代碼,連接客戶端原理流程圖,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-11-11
  • C#繪制橢圓的方法

    C#繪制橢圓的方法

    這篇文章主要介紹了C#繪制橢圓的方法,涉及C#圖形繪制的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • 漢字轉(zhuǎn)拼音軟件制件示例(漢字轉(zhuǎn)字母)

    漢字轉(zhuǎn)拼音軟件制件示例(漢字轉(zhuǎn)字母)

    這篇文章主要介紹了c#漢字轉(zhuǎn)拼音的方法,但不能判斷多音字,大家可以參考修改使用
    2014-01-01

最新評論

富源县| 湾仔区| 江门市| 田东县| 东丰县| 云梦县| 延川县| 寿阳县| 齐齐哈尔市| 庆安县| 新安县| 焦作市| 北碚区| 惠水县| 美姑县| 项城市| 新干县| 津南区| 开阳县| 嵊州市| 承德市| 米易县| 东平县| 泰宁县| 阿图什市| 突泉县| 马龙县| 安阳县| 芮城县| 鹤山市| 信丰县| 乃东县| 丰城市| 宁强县| 卓资县| 大邑县| 伊宁市| 汪清县| 大足县| 会泽县| 平罗县|