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

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

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

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)見(jià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));
  }
}

針頭碰撞檢測(cè)

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();
    }
  }
}

控制針的運(yùn)動(dòng)位置

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()
  {
     //針的實(shí)例化
    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);
    //重新加載場(chǎng)景
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  }
}

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

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

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

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

python俄羅斯方塊游戲集合

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

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

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    這篇文章主要介紹了C#編寫(xiě)游戲客戶端的實(shí)現(xiàn)代碼,連接客戶端原理流程圖,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    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

最新評(píng)論

青浦区| 五家渠市| 临沧市| 荆门市| 霞浦县| 十堰市| 洛宁县| 望奎县| 文安县| 满城县| 钟山县| 黔南| 宜川县| 高陵县| 玉山县| 昌黎县| 西昌市| 宝应县| 满城县| 昭通市| 连城县| 台安县| 昔阳县| 内丘县| 承德县| 信宜市| 南江县| 门源| 宣威市| 阜宁县| 江孜县| 双桥区| 兴城市| 梁平县| 万宁市| 城固县| 陆川县| 桂平市| 宝清县| 黄浦区| 青海省|