using UnityEngine;
using System.Collections;

/// <summary>
/// 相机控制
/// </summary>
public class CameraController : MonoBehaviour {

    /// <summary>
    /// 玩家
    /// </summary>
    public GameObject player;

    /// <summary>
    /// 玩家到相机的偏移
    /// </summary>
    private Vector3 offset;

    void Start ()
    {
        //计算偏移
        offset = transform.position - player.transform.position;
    }

    void LateUpdate ()
    {
        //设置相机的位置为玩家的位置加 玩家到相机的偏移
        transform.position = player.transform.position + offset;
    }
}

CameraController

using UnityEngine;

using UnityEngine.UI;

using System.Collections;

/// <summary>
/// 玩家控制
/// </summary>
public class PlayerController : MonoBehaviour {

    /// <summary>
    /// 移动速度
    /// </summary>
    public float speed;
    /// <summary>
    /// 吃掉的球的数量的文本
    /// </summary>
    public Text countText;
    /// <summary>
    /// 显示赢得比赛的文本
    /// </summary>
    public Text winText;

    /// <summary>
    /// Rigidbody
    /// </summary>
    private Rigidbody rb;
    /// <summary>
    /// 玩家吃掉的球的数量
    /// </summary>
    private int count;

    void Start ()
    {
        rb = GetComponent<Rigidbody>();

        count = ;

        SetCountText ();

        winText.text = "";
    }

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        rb.AddForce (movement * speed);
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag ("Pick Up"))
        {
            other.gameObject.SetActive (false);

            count = count + ;

            SetCountText ();
        }
    }

    /// <summary>
    /// 设置数量文本
    /// </summary>
    void SetCountText()
    {
        //更新显示数量的文本
        countText.text = "Count: " + count.ToString ();

        //如果数量大于等于12,
        )
        {
            winText.text = "You Win!";
        }
    }
}

PlayerController

using UnityEngine;
using System.Collections;

/// <summary>
/// 旋转小球
/// </summary>
public class Rotator : MonoBehaviour {

    void Update ()
    {
        transform.Rotate (, , ) * Time.deltaTime);
    }
}    

Rotator

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

/// <summary>
/// 教程信息
/// </summary>
public class TutorialInfo : MonoBehaviour
{
    /// <summary>
    /// 是否在开始时显示
    /// </summary>
    public bool showAtStart = true;

    /// <summary>
    /// 链接地址
    /// </summary>
    public string url;

    /// <summary>
    /// 覆盖层
    /// </summary>
    public GameObject overlay;

    public AudioListener mainListener;

    /// <summary>
    /// 开关 控制是否在开始时显示
    /// </summary>
    public Toggle showAtStartToggle;

    /// <summary>
    /// showLaunchScreen PlayerPrefs
    /// </summary>
    public static string showAtStartPrefsKey = "showLaunchScreen";

    /// <summary>
    /// 是否已经显示过了
    /// </summary>
    private static bool alreadyShownThisSession = false;

    void Awake()
    {
        if(alreadyShownThisSession)
        {
            StartGame();
        }
        else
        {
            alreadyShownThisSession = true;

            //如果prefs 有键,获取值,赋值给 showAtStart变量
            if (PlayerPrefs.HasKey(showAtStartPrefsKey))
            {
                showAtStart = PlayerPrefs.GetInt(showAtStartPrefsKey) == ;
            }

            //根据showAtStart 设置 Toggle 的勾选状态
            showAtStartToggle.isOn = showAtStart;

            //根据showAtStart 显示启动界面或者直接开始游戏
            if (showAtStart)
            {
                ShowLaunchScreen();
            }
            else
            {
                StartGame ();
            }
        }
    }

    /// <summary>
    /// 显示启动界面
    /// </summary>
    public void ShowLaunchScreen()
    {
        //游戏暂停
        Time.timeScale = 0f;
        mainListener.enabled = false;
        overlay.SetActive (true);
    }

    /// <summary>
    /// 打开链接地址
    /// </summary>
    public void LaunchTutorial()
    {
        Application.OpenURL (url);
    }

    /// <summary>
    /// 开始游戏
    /// </summary>
    public void StartGame()
    {
        overlay.SetActive (false);
        mainListener.enabled = true;
        //恢复正常的时间
        Time.timeScale = 1f;
    }

    /// <summary>
    /// 打开/关闭 是否在启动时显示
    /// </summary>
    public void ToggleShowAtLaunch()
    {
        showAtStart = showAtStartToggle.isOn;
        PlayerPrefs.SetInt(showAtStartPrefsKey, showAtStart ?  : );
    }
}

TutorialInfo

using UnityEngine;
using UnityEditor;
using System.Collections;

/// <summary>
/// 教程信息编辑器
/// </summary>
[CustomEditor(typeof(TutorialInfo))]    //指定这个编辑器脚本对应的脚本
public class TutorialInfoEditor : Editor
{
    /// <summary>
    /// ScriptObject.OnEnable
    /// </summary>
    void OnEnable()
    {
        //如果首选项里存在键
        if (PlayerPrefs.HasKey(TutorialInfo.showAtStartPrefsKey))
        {
            //读取值,根据值设置是否在开始时启用
            ((TutorialInfo)target).showAtStart = PlayerPrefs.GetInt(TutorialInfo.showAtStartPrefsKey) == ;
        }
    }

    /// <summary>
    /// Editor.OnInSpectorGUI
    /// 自定义检视面板
    /// </summary>
    public override void OnInspectorGUI()
    {
        //检查BeginChangeCheck()/EndChangeCheck() 里代码块内的控件是否有变
        EditorGUI.BeginChangeCheck();

        base.OnInspectorGUI();

        //如果有变化,重新获取并设置 showAtStartPrefsKey 的值
        if(EditorGUI.EndChangeCheck()) {
            PlayerPrefs.SetInt(TutorialInfo.showAtStartPrefsKey,((TutorialInfo)target).showAtStart ?  : );
        }
    }
}

TutorialInfoEditor

视频:https://pan.baidu.com/s/1jIHlTga

项目:https://pan.baidu.com/s/1c1Tffo

Roll a ball 学习的更多相关文章

  1. 学习unity的第一个小游戏(Roll the ball)的笔记

    1.摄像机的跟随运动,逻辑就是保持摄像机跟主角的距离不变(Undate()函数). offset=trandform.position-player.position. Undate() { tran ...

  2. Roll A Ball

    GameObject的添加就不细说了,地面,小球和碰撞小物体. 刚体组件(Rigidbody): 使物体能够模拟物理效果,比如重力,碰撞,推力等: 控制小球移动的脚本(Script,Ball的脚本): ...

  3. 关于Roll A Ball实例练习记录

    学习中不段进步! 游戏思路:通过键盘控制白色小球,让它"捡起"柠黄色方块,捡起一个加1分,全部捡起游戏胜利! 游戏对象: Ground:绿色地面 player:  小球 Obsta ...

  4. 1.1.0 Unity零基础入门2——Roll a Ball

    1. 游戏界面 2.代码 //FoodRotate - - 控制cube旋转 using System.Collections; using System.Collections.Generic; u ...

  5. Siki_Unity_1-2_Unity5.2入门课程_进入Unity开发的奇幻世界_Roll A Ball

    1-2 Unity5.2入门课程 进入Unity开发的奇幻世界 任务1:Roll A Ball项目简介 Unity官网的tutorial入门项目 方向键控制小球在平台上滚动,碰撞方块得分,消掉所有方块 ...

  6. URAL 1775 B - Space Bowling 计算几何

    B - Space BowlingTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  7. egret贝塞尔曲线运动

    class MtwGame { public constructor() { } private static _instance: MtwGame; public static get Instan ...

  8. Ethereum Learning Materials

    Home 注:本页为 EthFans 站内文章精选集.鉴于文章的采集范围较广,我们无法保证文章内容没有重复,也不能保证排列的顺序实现了最优的认识路径.我们只能说,这些文章是我们精挑细选后,确认可以长期 ...

  9. JAVAAPI学习之Calendar类;Calendar类set()、add()、roll()方法区别

    JAVAAPI学习之Calendar类 http://blog.csdn.net/myjlvzlp/article/details/8065775(写的很好,清晰易懂) Calendar类set(). ...

随机推荐

  1. centos7下nginx安全配置

    Linux服务器下nginx的安全配置   1.一些常识 linux下,要读取一个文件,首先需要具有对文件所在文件夹的执行权限,然后需要对文件的读取权限. php文件的执行不需要文件的执行权限,只需要 ...

  2. Convert the AScii to SAC file

    readtable *.txt w sac  filename.sac ch delta dela0 w over

  3. SharePoint Framework 把你的客户端web部件连接到SharePoint

    博客地址:http://blog.csdn.net/FoxDave 把你的web部件连接到SharePoint来访问SharePoint中的功能和数据,为终端用户提供更完整的体验.本篇会基于之前构 ...

  4. 牛客练习赛22 简单瞎搞题(bitset优化dp)

    一共有 n个数,第 i 个数是 xi  xi 可以取 [li , ri] 中任意的一个值. 设 ,求 S 种类数. 输入描述: 第一行一个数 n. 然后 n 行,每行两个数表示 li,ri.   输出 ...

  5. Linux文件系统命令 cp

    命令名:cp 功能:拷贝文件,把一个文件的内容拷贝到另外一个文件中去. eg: cp source_file dist_file renjg@renjg-HP-Compaq-Pro--MT:~$ cp ...

  6. uiautomator2 获取APP Toast内容

    前言:appium必须是1.6以上的版本 环境(安装和安装都可以运行成功,我也不确定要不要这个): 1.抓到toast需要安装uiautomator2,安装npm:npm install -g cnp ...

  7. filebeat成精之路

    https://www.cnblogs.com/jingmoxukong/p/8185321.html

  8. WHID Injector:将HID攻击带入新境界

    HID Attack是最近几年流行的一类攻击方式.HID是Human Interface Device的缩写,意思是人机接口设备.它是对鼠标.键盘.游戏手柄这一类可以操控电脑设备的统称. 由于电脑对这 ...

  9. Electron_01

    1.通过 https://electron.atom.io/  下载  electron-v1.4.15-win32-x64.zip 之后 2.通过 asar pack “你的项目文件夹” app.a ...

  10. Proxy --概述篇

    概述: Proxy 用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程. Proxy 可以理解成,在目标对象之前架设 ...