您当前在:首页 > 开发者 >

浏览量

开发者教程:零基础,17分钟制作AR丧尸游戏

开发者教程:零基础,17分钟制作AR丧尸游戏

发布时间:2018-04-09

零基础,17分钟制作AR丧尸游戏

视频教程,18分钟,点击右边观看:https://www.bilibili.com/video/av12499127/

1. 苹果设备

因为搭建需要在iOS 11上完成,你需要一个拥有A9或者A10芯片的机器,所以AR Kit只能在一下机器上:

-iPhone SE

-iPhone 6s

-iPhone 6s Plus

-iPhone 7

-iPhone 7 Plus

-iPad Pro

- 9.7-inch iPad 2017

2. 安装Xcode 9

你需要在电脑上安装Xcode 9 https://developer.apple.com/xcode/

3. 升级到 iOS 11

你需要在支持iOS和AR Kit的设备上安装iOS 11 ,推荐使用手机操作,方便匹配。

这里登陆注册 https://beta.apple.com/sp/betaprogram/guide#ios

这里下载profile https://beta.apple.com/sp/betaprogram/redemption#ios

然后回到手机设置 —> 通用 —> 软件更新,然后你就会看到iOS11更新选项了。点击更新,顺着流程完成更新下载。

4. 安装 Unity

官网下载:Unity - Download

注意安装 5.6版本以上的软件,我录制视频时使用的是 2017.1.0f3 的最新版本。

5. 开发

为表诚意,以下是Unity中修改的两个C#的文件,可以跟着视频自己敲,也可以参考这里的:

ZombieControl.cs

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class ZombieControl : MonoBehaviour {

private Animation animation;

private bool moving = false;

// Use this for initialization

void Start () {

animation = GetComponent ();

}

// Update is called once per frame

void Update () {

if (moving) {

transform.Translate (Vector3.forward * Time.deltaTime * (transform.localScale.x * .05f));

}

}

public void Walk(){

if (!animation.isPlaying) {

animation.Play ();

moving = true;

} else {

animation.Stop ();

moving = false;

}

}

public void LookAt(){

transform.LookAt (Camera.main.transform.position);

transform.eulerAngles = new Vector3 (0, transform.eulerAngles.y, 0);

}

public void Bigger(){

transform.localScale += new Vector3(1,1,1);

}

public void Smaller(){

if (transform.localScale.x > 1) {

transform.localScale -= new Vector3(1,1,1);

}

}

}

UnityARHitTestExample.cs

using System;

using System.Collections.Generic;

using UnityEngine.EventSystems;

namespace UnityEngine.XR.iOS

{

public class UnityARHitTestExample : MonoBehaviour

{

public Transform m_HitTransform;

bool HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes)

{

List hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest (point, resultTypes);

if (hitResults.Count > 0) {

foreach (var hitResult in hitResults) {

Debug.Log ("Got hit!");

m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform);

m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);

Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));

return true;

}

}

return false;

}

// Update is called once per frame

void Update () {

if (Input.touchCount > 0 && m_HitTransform != null)

{

var touch = Input.GetTouch(0);

if (touch.phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(0))

{

transform.localPosition = Vector3.zero;

var screenPosition = Camera.main.ScreenToViewportPoint(touch.position);

ARPoint point = new ARPoint {

x = screenPosition.x,

y = screenPosition.y

};

// prioritize reults types

ARHitTestResultType[] resultTypes = {

ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,

// if you want to use infinite planes use this:

//ARHitTestResultType.ARHitTestResultTypeExistingPlane,

ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,

ARHitTestResultType.ARHitTestResultTypeFeaturePoint

};

foreach (ARHitTestResultType resultType in resultTypes)

{

if (HitTestWithResultType (point, resultType))

{

return;

}

}

}

}

}

}

}

 

0

刚刚发布

深度VR观察

友情链接

Top ->