24511人加入学习
(76人评价)
Unity零基础入门 - 见缝插针(Unity2017)
价格 免费

在层次面板创建三个文件夹分别是,startpoint,spawnpoint,gamemanager和在canvas里的缩放里Z轴调到2

2.private Transform startpoint

   private Transform spawnpoint

   public GameObject pinprefab;

3.startpoint=GameObject.Find("startpoint").transform;

spawnpoint=GameObject.Find("spawnpoit").transform;

 

[展开全文]
水了 · 2021-03-28 · 该任务已被删除 0

分数显示的BUG可以将分数显示为圆圈子类的数量。

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

public class GameManger : MonoBehaviour
{
    //实例化
    private Transform startPoint;
    private Transform spawnPoint;
    private Transform circle;
    public GameObject pinPrefab;
    private Pin currentPin;
    private bool isGameOver;
    private int score;
    public Text scoreText;

    
    // Start is called before the first frame update
    void Start()
    {
        startPoint = GameObject.Find("StartPoint").transform;
        spawnPoint = GameObject.Find("SpawnPoint").transform;
        circle = GameObject.Find("Circle").transform;
        SpawnPin();

    }

    // Update is called once per frame
    void Update()
    {
        if (isGameOver)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            currentPin.Strarfly();
            SpawnPin();

        }
        //获取圆圈的子类数量作为分数
        score = circle.transform.childCount;
        scoreText.text = score.ToString();
    }
    private 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;
        isGameOver = true;

    }
}

 

[展开全文]
疯癫看不穿 · 2021-03-24 · 该任务已被删除 0

QAFWQ 

[展开全文]
洛河回眸 · 2021-02-09 · 该任务已被删除 0

transform.Rotate(new Vector3(0,0,speed*Time.deltaTime));

旋转

 

[展开全文]
464849494 · 2021-01-22 · 该任务已被删除 0

[展开全文]
春江晓景 · 2020-09-26 · 该任务已被删除 0

根据需求添加feng'zhuang

[展开全文]
挥望 · 2020-08-13 · 该任务已被删除 0

协程。

控制主摄像机的颜色。

Lerp插值方法。

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

应该插上去了再记分数。

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

针头添加collider

加不加刚体?

PinHead

OnTriggerInter

保证只运行一次。

碰撞必须有刚体。2d加2d的刚体。

注意给y

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

transform.parent.设置为父亲节点,跟随一起运动。

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

GameObjece.find。如果场景中有同名的。可能会出差错。

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

运动,

Vector3.MoveToWards();

感觉和插值差不多呢。

Vector3.Distance(当前位置,目标位置)

判断距离。

 

 

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

设置位置点。

StartPoint

SpawnPoint.

GameObject.Find.

将针制作成prefab.

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

将针做成prefab

针头加碰撞其,circle2d

 

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

控制小球旋转。

旋转是按照度数来的,一圈360度。

Rotate(new Vector3(0,0,speed*Time.deltaTime))

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

由3d到2d设置,摄像机正交

天空盒设置为none,选择2d 以及project setting,

EventSystem这个和Ui交互的时候用,不交互可以删除。

将Canvas 设置为WordSpace就可以进行缩小了

将Canvas 的摄像机设置为maincamera 这样图片和UI都是主摄像机渲染了。

Canvas 和 Circle分开,这样分数就不会跟着小球转了。

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

2D游戏

 

[展开全文]
Killernot · 2021-03-17 · 该任务已被删除 0

先创建

[展开全文]
SFI6 · 2020-04-24 · 该任务已被删除 0

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

public class GameManager : MonoBehaviour
{
    //准备发射的位置
    //public Transform startpos;
    //分数变量
    private int score = 0;
    //分数Text文本UI
    public Text scoretext;
    //预制体生成的位置
    public Transform pinpos;
    //预制体
    public GameObject pinprefab;
    //创建Pin脚本的成员
    private Pin FirePin;
    //单例(在其他脚本里可以用_instance点出该脚本的函数和成员变量)
    public static GameManager _instance;
    //游戏结束开关
    private bool IsGameOver = false;
    //摄像机
    private Camera maincamera;

    private void Awake()
    {
        //单例模式
        _instance = this;
    }
    // Start is called before the first frame update
    void Start()
    {
        //startpos = GameObject.Find("StarPos").transform;
        //得到生成位置PinPos的位置
        pinpos = GameObject.Find("PinPos").transform;
        //获取摄像机
        maincamera = Camera.main;
        //实例化预制体
        AddPin();
    }

    // Update is called once per frame
    void Update()
    {
        //如果IsGameOver开关为true就return掉,不执行后面的逻辑
        if (IsGameOver==true)
            return;
        //鼠标左键按下
        if (Input.GetMouseButtonDown(0))
        {
            //分数增加
            score++;
            //分数显示文本内容为score
            scoretext.text = score.ToString();
            //调用Pin脚本里的StarFly函数
            FirePin.StarFly();
            //实例化预制体
            AddPin();
        }
    }

    void AddPin()
    {
        //预制体实例化
        FirePin = GameObject.Instantiate(pinprefab, pinpos.position, pinprefab.transform.rotation).GetComponent<Pin>();
    }

    public void GameOver()
    {
        //如果IsGameOver为true就return掉,不执行后面的逻辑
        if (IsGameOver)
            return;
        //让Rotation脚本不可用(不执行--旋转)
        GameObject.Find("Circle").GetComponent<Rotation>().enabled = false;
        //游戏结束开关打开,并执行协程
        IsGameOver = true;
        StartCoroutine("GameOverAnimation");
    }

    //协程,播放游戏结束页面缓动动画并重新加载场景开始游戏
    IEnumerator GameOverAnimation()
    {
        while (true)
        {
            //摄像机背景色的差值运算
            maincamera.backgroundColor = Color.Lerp(maincamera.backgroundColor, Color.gray, 3 * Time.deltaTime);
            //摄像机的orthographicSize的差值运算
            maincamera.orthographicSize = Mathf.Lerp(maincamera.orthographicSize, 3, 3 * Time.deltaTime);
            //当Size到达3时就中断这个while循环
            if (Mathf.Abs(maincamera.orthographicSize - 3) <= 0.02f)
            {
                break;
            }
            //等待一帧
            yield return 0;
        }
        //等待两秒之后加载场景重新开始游戏
        yield return new WaitForSeconds(2);
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
}

[展开全文]
昊杰Horjye · 2020-04-19 · 该任务已被删除 0

private bool IsFly = false;
    private bool IsReady = false;
    private Transform startpos;
    private Transform circle;
    public float speed = 15f;

    private Vector3 targetpos;
    // Start is called before the first frame update
    void Start()
    {
        startpos = GameObject.Find("StarPos").transform;
        circle = GameObject.Find("Circle").transform;
        targetpos =new Vector3(circle.position.x, 0, circle.position.z);
    }

    // Update is called once per frame
    void Update()
    {
        if (IsFly==false)
        {
            if (IsReady==false)
            {
                transform.position = Vector3.MoveTowards(transform.position, startpos.position, speed * Time.deltaTime);
                if (Vector3.Distance(transform.position, startpos.position) <= 0.05f)
                {
                    IsReady = true;
                }
            }

        }
        else
        {
            transform.position = Vector3.MoveTowards(transform.position, targetpos, speed * Time.deltaTime);
            if(Vector3.Distance(transform.position,targetpos)<=0.03f)
            {
                transform.position = targetpos;
                IsFly = false;
                transform.parent = circle;
            }
        }
    }

    public void StarFly()
    {
        IsFly = true;
        IsReady = true;
    }

[展开全文]
昊杰Horjye · 2020-04-19 · 该任务已被删除 0

授课教师

SiKi学院老师

课程特色

下载资料(1)
视频(12)