【Unity】Unity 2D游戏开发(三)2D游戏常用功能及插件

27 篇文章 8 订阅
5 篇文章 2 订阅

377节附近开始的2D游戏实例,基础的功能开发可以参考。

碰撞忽略

private void Start()
{
	// 让第八层和第九层忽略碰撞,此段代码可以写在通用脚本内
	Physics2D.IgnoreLayerCollision(8, 9);
}

在这里插入图片描述
在这里插入图片描述

Easy Touch插件

可以用来做摇杆,功能简单,不多写了。
插件中有一些关于event的实例脚本(JoystickEnent、EasyJoystick等),可以用来参考。

触摸事件

可以看看API中的Input类、Touch类,多点触控可以看一下GetTouch方法。
TouchPhase触摸相位(枚举),通过这个枚举来判断触摸的状态:

枚举值描述
Began手指触摸了屏幕。
Moved手指在屏幕上进行了移动。
Stationary手指正在触摸屏幕但尚未移动。
Ended从屏幕上抬起了手指,只是最后一个触摸阶段。
Canceled系统取消了对触摸的跟踪,如用户把屏幕放到脸上或者touch点过多时,这是一个触摸的最后状态。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TouchPhaseExample : MonoBehaviour
{
    public Vector2 startPos;
    public Vector2 direction;

    public Text m_Text;
    string message;

    void Update()
    {
        //Update the Text on the screen depending on current TouchPhase, and the current direction vector
        m_Text.text = "Touch : " + message + "in direction" + direction;

        // Track a single touch as a direction control.
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);

            // Handle finger movements based on TouchPhase
            switch (touch.phase)
            {
                //When a touch has first been detected, change the message and record the starting position
                case TouchPhase.Began:
                    // Record initial touch position.
                    startPos = touch.position;
                    message = "Begun ";
                    break;

                //Determine if the touch is a moving touch
                case TouchPhase.Moved:
                    // Determine direction by comparing the current touch position with the initial one
                    direction = touch.position - startPos;
                    message = "Moving ";
                    break;

                case TouchPhase.Ended:
                    // Report that the touch has ended when it ends
                    message = "Ending ";
                    break;
            }
        }
    }
}

Unity Remote远程调试

手机装APP,PC端装安卓环境。

AR(AugmentedReality)增强现实

常用插件:

  • Vuforia 高通,不支持Mac PC
  • EasyAR 国内开发的AR插件,使用方便,移动设备、PC都可以
  • ARToolKit 开发难度较大,使用人少
  • Metaio 被苹果收购

EasyAR插件

需要用公司信息(Bundle ID或Package Name)到官网去注册,获取Key以后才可以使用。

读取文本文件

TextAsset.text此方式只能一次性读取文件中的所有内容。

读取远程文件

public class TestWWW : MonoBehaviour
{
	public string url = "http://www.xxx.com/xxx/xxx.jpg";
	IEnumerator start()
	{
		WWW www = new WWW(URL);
		yield return www;
		renderer.material.mainTexture = www.texture;
	}
}

更多内容请查看总目录【Unity】Unity学习笔记目录整理

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值