2021-04-27

见缝插针
**

加粗样式

**
1.创建2D项目,导入素材 将圆拖入Hierarchy面板。
2. 写个代码让圆旋转,命名为Rotate,将脚本挂到圆的身上。
3. 代码如下;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotate : MonoBehaviour
{
public float speed = 100;//圆旋转速度
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    transform.Rotate(new Vector3(0, 0, -speed * Time.deltaTime));

}

}
4.创建两个空物体(Create Empty)命名为Inspoint (生成针的位置)和Startpoint针等待位置。自己调位置。将Select icon设置成灰色。
5.将针拖到层级面板中,添加Rigbody2D,将重力(Gravity)设置为0。
6.创建新代码,命名为Pin,代码挂载到pin上。代码如下;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pin : MonoBehaviour
{
public bool isReah = false;
public bool isFly = false;
private Transform starPoint;
private Transform dunPos;//圆的位置
public float speed = 5;//针移动的速度
private Vector3 endPoint;//结束位置
// Start is called before the first frame update
void Start()
{
starPoint = GameObject.Find(“StartPoint”).transform;
dunPos = GameObject.Find(“dun”).transform;
endPoint = dunPos.position;
endPoint.y -= 4f;
}

// Update is called once per frame
void Update()
{
    if (isFly == false)
    {
        if (isReah == false)
        {
            transform.position = Vector3.MoveTowards(transform.position, starPoint.position, speed * Time.deltaTime);
            if (Vector3.Distance(transform.position, starPoint.position) < 0.05f)
            {
                isReah = true;
            }
        }
    }
    else
    {
        transform.position = Vector3.MoveTowards(transform.position, endPoint, speed * Time.deltaTime);
        if (Vector3.Distance(transform.position, endPoint) < 0.05)
        {
            isFly = false;
            transform.parent = dunPos;
        }
    }
}
public void StartFly()
{
    isFly = true;
    isReah = true;
}

}
7.创建针的预设体,直接把层级面板中的Pin拖到Prafabs里。
8.创建空物体命名为,GameManger。创建Text ,拖到圆中心。
9.创建代码命名为GameManger,把代码挂到GameManger身上。代码如下;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameManger : MonoBehaviour
{
public GameObject PinPrefab;//针的预设物
private Transform insPoint;//实例化位置
public Pin currentPin;//当前针
public bool isover;
public GameObject dun;
public Text scoreText;//分数显示的文本
public int score = 0;//分数
public Camera mainCamera;
public int speed = 3;//渐变的速度
// Start is called before the first frame update
void Start()
{
insPoint = GameObject.Find(“InsPoint”).transform;
InsPin();
mainCamera = Camera.main;//获取主相机
}

// Update is called once per frame
void Update()
{
    if (isover) return;
    //获取鼠标点击 0-鼠标左键  1-鼠标右键  2-鼠标中键
    if (Input.GetMouseButtonDown(0))
    {
        score++;
        scoreText.text = score.ToString();
        currentPin.StartFly();
        //Debug.Log("鼠标左键点击了一下");
        InsPin();
    }
}

internal static object Find(string v)
{
    throw new NotImplementedException();
}

//实例化针
void InsPin()
{
    currentPin = GameObject.Instantiate(PinPrefab, insPoint.position, PinPrefab.transform.rotation).GetComponent<Pin>();
}
public void GameOver()
{
    if (isover) return;
    dun.GetComponent<Rotate>().enabled = false;
    StartCoroutine(GameOverAnimation());//开启协程
    isover = 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.01)
        {
            break;
        }
        yield return 0;
    }
    yield return new WaitForSeconds(2);
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

}
10.回到unity中,将针的预制体拖到Pin 拖到prefab里,将圆拖入dun中,text拖入Score Text 中,相机拖入Main cemera中。
11.游戏结束,创建代码PinHead,将他挂到针的身上。代码如下;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PinHead : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == “jian”)
{
GameObject.Find(“GameManger”).GetComponent().GameOver();
//游戏结束
}
}
}
10.回到unity中,选中针的预制体点击Add Component,添加Circle collider2d组件并勾选Is Tirgger。点击Edit Collider在Scene视图中将碰撞体缩放到针的末尾。然后点击Apply应用。然后创建一个名为“jian”的tag(标签)。
11运行游戏就完成了。大家要细心看好每一步哦!

Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、中小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值