国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

unity——小球酷跑游戲制作

這篇具有很好參考價值的文章主要介紹了unity——小球酷跑游戲制作。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

課堂課程記錄——小球滾動

所有變量與物體名的命名原則都是見名知意

一、創(chuàng)建一個unity項目
二、Create所需3Dobject
1.Player
unity——小球酷跑游戲制作2.walls
unity——小球酷跑游戲制作
三、添加屬性
1.添加在Player上
a.添加Rigidbody組件unity——小球酷跑游戲制作
b.添加new script組件,并命名為PlayMove,代碼如下:

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

public class playMove : MonoBehaviour
{
    public Rigidbody rd;
    public float speadAutoMove=5;
    public float speadMoveUpandDown=20;
    // Start is called before the first frame update
    void Start()
    {
        rd=gameObject.GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        PlayerAutoMove();
        PlayerMoveUpandDown();
    }
    private void PlayerAutoMove(){
        rd.AddForce(Vector3.right*speadAutoMove);   //前進
    }
    private void PlayerMoveUpandDown()
    {
        float v=Input.GetAxis("Vertical");  //上下
        rd.AddForce(v*Vector3.up*speadMoveUpandDown);//給一個上下的力量

    }
}

2.添加到walls上
a.首先create empty將wall包含
unity——小球酷跑游戲制作
b.在Wall上添加new script組件,代碼如下:

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

public class wallControl : MonoBehaviour
{
    private float offset;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        offset=gameObject.transform.position.x-player.transform.position.x;
    }

    // Update is called once per frame
    void Update()
    {
        FollowPlayMove();
    }
    void FollowPlayMove(){
        gameObject.transform.position=new Vector3(player.transform.position.x+offset,0,0);
    }
}

3.實現(xiàn)相機跟隨
a.在相機上添加new script 組件并命名為cameraControl,代碼如下:

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

public class cameraControl : MonoBehaviour
{
    public GameObject player;
    private float offset_camera;
    // Start is called before the first frame update
    void Start()
    {
        offset_camera=gameObject.transform.position.x-player.transform.position.x;
    }

    // Update is called once per frame
    void Update()
    {
        FollowCameraMove();
    }
    void FollowCameraMove(){
        gameObject.transform.position=new Vector3(offset_camera+player.transform.position.x,gameObject.transform.position.y,gameObject.transform.position.z);
    }
}

b.將script中設置的player變量賦值:
unity——小球酷跑游戲制作
至此基本的小球滾動游戲就完成了。
unity——小球酷跑游戲制作

繼續(xù)上節(jié)課的內容:

4.將player的形狀改為球形
左鍵選中player的屬性:unity——小球酷跑游戲制作
將mesh屬性由cube改為sphere
5.創(chuàng)建障礙預制體
a.先創(chuàng)建一個3D物體cube,將其命名為barrier。
b.在project的asset中創(chuàng)建prefab預制體文件
unity——小球酷跑游戲制作
并將之前創(chuàng)建的barrier直接拖拽到prefab中。
若對prefab預制體的作用不理解的話,可訪問如下鏈接:
預制體的制作與功能
若barrier物體變?yōu)樗{色,則創(chuàng)建成功。
unity——小球酷跑游戲制作
6.隨機生成障礙物
a.創(chuàng)建一個空物體,然后命名為barrierControl。
unity——小球酷跑游戲制作
b.在該物體上添加new script的組件,C#代碼如下:

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

public class BarrierControl : MonoBehaviour {
    public int barrierInterval=5;
    public GameObject player;
    public GameObject CurrentBarrier;
    public GameObject BarrierPre;
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        AutoCreatBarrier();

    }
    // 障礙物自動生成
    public void AutoCreatBarrier()
    {
        if(player.transform.position.x>CurrentBarrier.transform.position.x)
        {
            //生成新的障礙物
            float targetX = CurrentBarrier.transform.position.x + barrierInterval;
            float targetY = RandomBarrierPosition();
            Vector3 targetPos = new Vector3(targetX,targetY,0);
            GameObject g = Instantiate(BarrierPre,targetPos,Quaternion.identity);
            //隨機大小
           g.transform.localScale = new Vector3(g.transform.localScale.x, RandomBarrierSize((int)g.transform.position.y), g.transform.localScale.z);
            //判斷障礙更換
            CurrentBarrier = g;
        }
    }
    //障礙隨機大小
    public float RandomBarrierSize(int r)
    {
        int rAbs = Mathf.Abs(r);
        if(rAbs==0)
        {
            return 6;
        }
        else
        {
            return (3-rAbs)*2+1;
        }
    }
    //障礙物隨機位置
    public float RandomBarrierPosition()
    {
       int r = Random.Range(-3,3);
        Debug.Log(r);
        return r;
    }

}

到目前為止障礙物就能不斷的在與小球的距離控制下產(chǎn)生了。
7.障礙的清除
a.在之前的wall文件夾中創(chuàng)建一個新cube物體,命名為trigger,控制大小長度在略小于上下wall之間,以便過濾掉與其接觸的barrier(切記不要接觸上下的wall,否則游戲一開始就會將上下的wall給消除,小球一下就掉下去了)。
unity——小球酷跑游戲制作
b.右鍵選中trigger,在右側的屬性欄,移除Cube(Mesh Filter)和Mesh Renderer屬性。
unity——小球酷跑游戲制作
使trigger成為透明狀態(tài):
unity——小球酷跑游戲制作

c.給trigger添加new script組件,C#代碼如下:

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

public class AutoDestoryBarriers : MonoBehaviour {

    private void OnTriggerEnter(Collider other)
    {
        Destroy(other.gameObject);
    }
}

8.給障礙物添加隨機產(chǎn)生顏色功能

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

public class BarrierColor : MonoBehaviour {
    public Material[] barrierMaterial;
	// Use this for initialization
	void Start () {
        int i = Random.Range(0,barrierMaterial.Length);
        gameObject.GetComponent<Renderer>().material = barrierMaterial[i];
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}

unity——小球酷跑游戲制作

9.碰到障礙物顏色提示
unity——小球酷跑游戲制作
C#代碼如下:

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

public class PlayerColorControl : MonoBehaviour
{
        private void OnCollisionEnter(Collision collision)
        {
           // Debug.Log("1");
           //分數(shù)減少
           UIcontrol._instance.AddScore(-10);
            gameObject.GetComponent<Renderer>().material.color=Color.red;
        }
        private void OnCollisionExit(Collision collision)
        {
            gameObject.GetComponent<Renderer>().material.color=Color.white;
        }
}

9.分數(shù)記錄
unity——小球酷跑游戲制作
C#代碼如下:

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

public class UIcontrol : MonoBehaviour
{
   public Text scoreText;
   public int score=0;


    //單列模式
    public static UIcontrol _instance;
    private void Awake()
    {
        _instance=this;
    }
    public void AddScore(int x)
    {
        score+=x;
        scoreText.text="得分:"+score;
    }
}

并在barrierControl中添加如下代碼進行分數(shù)增加
unity——小球酷跑游戲制作
在Playcolorcontrol中添加分數(shù)減少代碼:
unity——小球酷跑游戲制作
完整畫面如下:
unity——小球酷跑游戲制作

以上小球酷跑課程內容就結束了,稍后我會對游戲進行進一步的完善功能。文章來源地址http://www.zghlxwxcb.cn/news/detail-423062.html

到了這里,關于unity——小球酷跑游戲制作的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • Unity學習記錄:制作雙屏垃圾分類小游戲

    Unity學習記錄:制作雙屏垃圾分類小游戲

    要實現(xiàn)的功能 游戲操作 在規(guī)定時間內,垃圾通過拖拽進入正確垃圾桶的容器,垃圾在這里消失,飛入第二個屏上對應垃圾桶的位置并實現(xiàn)加分和加時間的效果,垃圾拖拽進入不正確的垃圾桶,垃圾會返回到原來的位置,同時,相應的時間也會減少 勝利和失敗的條件: 勝利:

    2024年02月03日
    瀏覽(19)
  • unity小球吃金幣小游戲

    unity小球吃金幣小游戲

    鏈接放在這里 unity小球吃金幣小游戲-Unity3D文檔類資源-CSDN下載 這是我在學完虛擬現(xiàn)實技術這門課程后利用unity所做的小球吃金幣小游戲,里面有源碼和作品源文件,用u更多下載資源、學習資料請訪問CSDN下載頻道. https://download.csdn.net/download/m0_57324918/85604051 1創(chuàng)建Roll A Ball小球吃

    2023年04月08日
    瀏覽(23)
  • 【Unity】小球吃方磚小游戲

    【Unity】小球吃方磚小游戲

    目錄 游戲背景 游戲開發(fā) ????????2.1場景布置 ????????2.2小球運動 ????????2.3鏡頭跟蹤 ????????2.4吃掉方磚 ? ? ? ? 2.5結束提示 游戲錄制 ? ? ? ? ? 用wasd(↑←↓→)操控小球進行平面滑動,小球觸碰會原地打轉的立方體后立方體會消失,消除5個小球后提示

    2024年02月09日
    瀏覽(18)
  • Unity和C#游戲編程入門:創(chuàng)建迷宮小球游戲示例

    Unity和C#游戲編程入門:創(chuàng)建迷宮小球游戲示例

    ?? 個人網(wǎng)站:【工具大全】【游戲大全】【神級源碼資源網(wǎng)】 ?? 前端學習課程:??【28個案例趣學前端】【400個JS面試題】 ?? 尋找學習交流、摸魚劃水的小伙伴,請點擊【摸魚學習交流群】 當涉及到Unity和C#游戲編程入門時,以下是一些示例代碼,可以幫助初學者更好地理

    2024年02月08日
    瀏覽(18)
  • c++編寫天天酷跑游戲

    素材加Q群:723550115 Start importing material (background picture) Create a graph window and define macros for the window Import game background (scroll cycle) Local modularization Game background coordinates ? The picture is the Y coordinate of motion, and the definition amount is constantly changed to keep the last y coordinate change initialization

    2024年02月16日
    瀏覽(24)
  • Unity制作虛擬主機裝機模擬器(課程設計)

    Unity制作虛擬主機裝機模擬器(課程設計)

    1.設計階段 1.1需求分析 本虛擬裝機系統(tǒng)是為了幫助用戶學習計算機的組裝過程,提供動手組裝、教學模式和零件介紹三種模式。在零件介紹中,用戶可以通過語音和文字介紹了解不同電腦零件的功能和名稱。在教學模式中,用戶可以觀看動畫短片,了解計算機的發(fā)展和組裝計

    2024年01月21日
    瀏覽(124)
  • 簡單的天天酷跑小游戲實現(xiàn)
  • 【unity】快速了解游戲制作流程-制作九宮格簡單游戲demo

    【unity】快速了解游戲制作流程-制作九宮格簡單游戲demo

    ? ? ? ? hi~大家好呀!歡迎來到我的unity學習筆記系列~,本篇我會簡單的記錄一下游戲流程并且簡單上手一個通過九宮格移動到指定位置的小游戲,話不多說,我們直接開始吧~ ???????? ????????本篇源自我看B站一位up主的視頻所做的筆記,感興趣的可以去看原視頻哦

    2023年04月08日
    瀏覽(38)
  • qt-有趣的小球游戲大球吃小球

    qt-有趣的小球游戲大球吃小球

    https://download.csdn.net/download/u013083044/88861691?spm=1001.2014.3001.5503

    2024年02月22日
    瀏覽(16)
  • python制作跳躍的小球

    11.1.安裝pygame庫 pip install pygame 11.2.加載模塊初始化 11.3.創(chuàng)建窗口 作用:創(chuàng)建游戲窗口 常見的內置方法: 方法 作用 pygame.dispaly. init() 初始化display pygame.dispaly. quit() 結束display模塊 pygame.dispaly. get_init() 判斷是否初始化 pygame.dispaly. get.surface() 獲取當前surface對象 pygame.dispaly. flip

    2024年02月03日
    瀏覽(15)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包