c语言见缝插针小游戏,Unity实现见缝插针小游戏
本文实例为大家分享了Unity实现见缝插针游戏的具体代码,供大家参考,具体内容如下
控制小球旋转
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateSelf : MonoBehaviour {
//每秒旋转90度
public float speed = 90;
// Update is called once per frame
void Update () {
//绕Z轴顺针旋转
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().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();
}
public void GameOver()
{
if (isGameOver) return;
GameObject.Find("Circle").GetComponent().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);
}
}
游戏初始状态和运行结果
更多有趣的经典小游戏实现专题,分享给大家:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
c语言见缝插针小游戏,Unity实现见缝插针小游戏相关推荐
- 【Unity】U3D TD游戏制作实例(三)相机管理器、生成敌人优化、敌人血槽小组件
文章目录 相机管理器 调整相机 敌人类优化 融合导航测试代码 敌人移动速度 销毁对象 加载敌人配置 敌人生成方式优化 血槽组件 相机管理器 调整相机 首先将主相机调整为正交镜头,这样可以防止模型畸变. ...
- unity期末作业-拼图游戏
unity期末作业-拼图游戏 unity期末作业-拼图游戏,有22,33,44,55四种模式供选择,有开始按钮,结束提示等等内容,如下图所示: 资源下载链接:https://download.csdn ...
- unity小游戏制作之见缝插针
unity小游戏制作之见缝插针 先看效果图这个游戏是一个入门的小游戏,主要技术就是圆盘的旋转,针跟随圆盘旋转以及分数累加等 游戏先拖入一个圆,更改格式为2D然后建立脚本使其转动 public clas ...
- unity课设小游戏_Unity制作20个迷你小游戏实例训练视频教程
本教程是关于Unity制作20个迷你小游戏实例训练视频教程,时长:20小时,大小:3.8 GB,MP4高清视频格式,教程使用软件:Unity,附源文件,作者:Raja Biswas,共97个章节,语言 ...
- 见缝插针小程序php,抖音小程序怎么开通
僵尸过马路.砖块破坏者.最囧游戏1.最囧游戏2.最囧游戏3 inside.掘地求升(正版).纪念碑谷1.纪念碑谷2.完美贴合-fit 地狱边境(limbo).跳舞的线.采油小怪物.采油小怪物2.八分音 ...
- 《卡耐基三部曲》(Yanlz+VR云游戏+Unity+SteamVR+云技术+5G+AI+人性的弱点+人性的优点+语言的突破+术业有专攻+世界观+人生观+价值观+志同道合+不卑不亢+立钻哥哥++==)
版本 作者 参与者 完成日期 备注 YanlzMgr_Carnegie_V01_1.0 严立钻 2021.04.09 ##<卡耐基三部曲>发布说明: ++++"卡耐基三部曲&qu ...
- c语言使用easyX图形库制作打气球小游戏
大一c语言使用easyX图形库制作打气球小游戏 如果你是入门easyX图形库,那么这个打气球小游戏将会是和不错的入门项目选择,easyX开创了可视化窗口,使用户更加直观的了解到对象的变化,总代码以及素 ...
- unity转微信小程序小游戏
参考连接 https://blog.csdn.net/weixin_38777563/article/details/123083150 unity转换小游戏插件下载地址 https://github ...
- Unity对H5小游戏开发的支持——Project Tiny
随着微信小游戏跳一跳的大火,游戏市场对于H5小游戏的开发逐渐火爆,作为一名Unity游戏开发从业者,大家对于Unity中开发小游戏的支持也很关注!近日Unity官方发布了Project Tiny ...
最新文章
- 【救援过程】升级openssl导致libcrypto.so.1.1动态库不可用
- java map赋值_java 中的map怎么没有办法赋值?
- 华为云服务器 大文件,云服务器上传大文件
- 为了OFFER系列 | 牛客网美团点评数据分析刷题
- 关于equals和hashcode方法
- bs4 乱码_Python BeautifulSoup中文乱码问题的2种解决方法
- leetcode - 64. 最小路径和
- 使用will和would来提出请求_42
- 未来感十足:小米发布四曲面屏幕专利
- vue.js原生组件化开发(一)——组件开发基础
- ubuntu19 磁盘分区管理及磁盘挂载
- Html5之canvas重叠矩形、getContext、fillStyle、fillRect
- 在线 excel 产品技术调研
- WebStorm下载其他版本(历史版本)
- esp8266基本使用 - WebServer
- PyTorch的安装与一些问题处理
- web前端入门到实战:HTML字符实体,转义字符串
- Git详解之服务部署
- java 建一个car_大学java习题 :定义一个汽车类car
- IE8和IE9对于前端来说有什么区别