unity survival shooter ZSpace
一、工程准备
1、官网下载支持Unity4.6版本 survival shooter资源;
2、确保你的ZSPACE有最新的SDK install
http://developer.zspace.com/downloads
using System.Collections;
public class stylus : MonoBehaviour {
private ZSCore zs_core_;
private ZSCore.TrackerTargetType target_type = ZSCore.TrackerTargetType.Primary;
private LineRenderer stylus_render_line;
private Vector3 projection_point_;
private const float cam_ray_length_=100.0f;
public void Start()
{
zs_core_ = GameObject.Find("ZSCore").GetComponent<ZSCore>();
zs_core_.Updated += new ZSCore.CoreEventHandler(OnCoreUpdated);
stylus_render_line = GetComponent<LineRenderer>();
}
public Vector3 GetPonterLocation()
{
return projection_point_;
}
private void OnCoreUpdated(ZSCore sender)
{
UpdateStylusPose();
UpdateProjectionPoint();
DrawStylusBeam();
}
private void UpdateStylusPose()
{
Matrix4x4 pose= zs_core_ .GetTrackerTargetWorldPose(target_type );
transform .position = new Vector3 (pose .m03,pose .m13 ,pose .m23);
transform .rotation = Quaternion.LookRotation (pose .GetColumn(2),pose .GetColumn(1));
}
private void UpdateProjectionPoint()
{
RaycastHit hit_;
if (Physics.Raycast(transform.position, transform.forward, out hit_, cam_ray_length_))
{
projection_point_ = hit_.point;
}
else
{
Ray ray = new Ray(transform.position, transform.forward);
projection_point_ = ray.GetPoint(cam_ray_length_);
}
}
private void DrawStylusBeam()
{
stylus_render_line.SetPosition(0, transform.position);
stylus_render_line.SetPosition(1, projection_point_);
}
}
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed = 6.0f;
public stylus stylusScript;
private ZSCore zs_core;
private ZSCore.TrackerTargetType target_type_ = ZSCore.TrackerTargetType.Primary;
private Animator anim_;
private Rigidbody player_rigidbody_;
void Awake()
{
anim_ = GetComponent<Animator>();
player_rigidbody_ = GetComponent<Rigidbody>();
zs_core = GameObject.Find("ZSCore").GetComponent<ZSCore>();
}
void FixedUpdate()
{
bool moved_ = Move();
Turning();
Animating(moved_);
}
bool Move()
{
bool did_move = false;
float h_ = 0.0f;
float v_ = 0.0f;
Vector3 destination_ = new Vector3(0.0f, 0.0f, 0.0f);
//moving with the stylus? check if 2nd or 3rd stylus buttons are pressed
if (zs_core.IsTrackerTargetButtonPressed(target_type_, 1) ||
zs_core.IsTrackerTargetButtonPressed(target_type_, 2))
{
if (zs_core.IsTrackerTargetButtonPressed(target_type_, 2))
{
//move backwards with button3
destination_ = Vector3.MoveTowards(transform.position, stylusScript.GetPointerLocation(),
-speed * Time.deltaTime);
}
//move backwards with button2
else
{
destination_ = Vector3.MoveTowards(transform.position, stylusScript.GetPointerLocation(),
-speed * Time.deltaTime);
}
//cancel any movement
destination_.Set(destination_.x, 0.0f, destination_.z);
//Note: this will always be true,as the stlyus beam doesn't enter inside
//the player to reach its origin point
did_move = transform.position != destination_;
player_rigidbody_.MovePosition(destination_);
}
else //otherwise check for keyboard input
{
h_ = Input.GetAxisRaw("Horizontal");
v_ = Input.GetAxisRaw("Vertical");
destination_.Set(h_, 0.0f, v_);
destination_ = destination_.normalized * speed * Time.deltaTime;
player_rigidbody_.MovePosition(transform.position + destination_);
did_move = h_ !=0.0f||v_ !=0.0f;
}
return did_move;
}
void Turning()
{
Vector3 pointer_location_ = stylusScript.GetPointerLocation();
Vector3 player_to_stylus_ = pointer_location_ - transform.position;
Quaternion newRotation = Quaternion.LookRotation(player_to_stylus_);
//Don't turn in x or z axes
newRotation.x = 0;
newRotation.z = 0;
//player_rigidbody_.MoveRotate(newRotation);
}
void Animating(bool moved)
{
anim_.SetBool("IsWalking", moved);
}
}
using UnityEngine.UI;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int statingHealth = 100;
public int currentHealth;
public Slider healthSlider;
public ImageEffectOpaque damageImage;
public AudioClip deathClip;
public float flashSpeed=5.0f;
public Color flashcolour=new Color (1.0f,0.0f,0.0f,0.1f);
public float vibrateTime=0.4f;
private ZSCore zs_core_;
private ZSCore .TrackerTargetType target_type= ZSCore.TrackerTargetType .Primary ;
private Animator anim;
private AudioSource player_audio;
private PlayerMovement player_movement_;
private PlayShooting player_shooting_;
private bool is_dead_;
private bool is_damaged;
void Awake()
{
anim = GetComponent<Animator>();
player_audio =GetComponent <AudioSource >();
player_movement_=GetComponent <PlayerMovement>();
player_shooting_= GetComponent <PlayShooting >();
currentHealth = statingHealth ;
zs_core_ = GameObject.Find ("ZSCore").GetComponent<ZSCore>();
}
void Update()
{
if(is_damaged)
{
damageImage .color=flashcolour ;
zs_core_ .SetTrackerTargetVibrationEnabled(target_type,true );
zs_core_ .StartTrackerTargetVibration(target_type ,vibrateTime ,0.0f,1);
}
else
{
damageImage .color=Color .Lerp (damageImage .color,Color .clear ,flashSpeed*Time .deltaTime );
}
is_damaged=false ;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
unity survival shooter ZSpace相关推荐
- unity——Survival Shooter:环境角色
0.写在前面 Survival Shooter是一个持续很久的项目,实际上也是正经进入untiy3d后的第一个正经的游戏,但是学习了很长时间,其中也因为各种原因断过,终于把他做出来了,撒花!那么接下来 ...
- unity——Survival Shooter:攻击敌人
8.攻击敌人 现在我们要赋予可爱的小主人公夺取敌人生命的能力. now 我们要做一个炫酷的宇宙无敌螺旋牛逼激光枪.我们的小人物已经在手里拿着枪了,我们需要做的就是让他能射出东西:让他能发出声音:让他能 ...
- 噩梦射手 安装包资源包提供下载 Unity官方教程 Survival Shooter 资源已经失效了!? Unity3D休闲射击类游戏《Survival Shooter》完整源码
Unity官方教程 (Survival Shooter) 资源已经失效了! 可能是版本太老了 中文名叫噩梦射手? 找了半天找了这个版本 的 放到这里吧 [这个游戏主角是必死的,就看能坚持多久啦] 网 ...
- Unity3D休闲射击类游戏《Survival Shooter》完整源码
Unity3D休闲射击类游戏<Survival Shooter>完整源码分享给大家学习,这个对于那些想要制作u3d射击类游戏有很大帮助. 运行环境是:Unity5.3.1 下载地址: ht ...
- 通过命令行启动Unity并激活ZSpace和OpenGL
首先,打开Dos界面,Windows+R组合键,在打开界面中输入cmd,然后运行. 然后,在打开的界面中输入Unity的安装路径,1.Window系统C:\Program Files (x86)\Un ...
- 通过命令行启动Unity并激活ZSpace和OpenGL(从新账户转)
首先,打开Dos界面,Windows+R组合键,在打开界面中输入cmd,然后运行. 然后,在打开的界面中输入Unity的安装路径, 1.Window系统C:\Program Files (x86)\U ...
- Unit5 Survival Shooter笔记3
调用游戏脚本 Unity作用,脚本也是一个GameObject的基本的Component,也可以使用GetComponent<>()进行调用,<>内部输入脚本的名称即可.可以调 ...
- Unity笔记之zSpace开发
zSpace开发个人感觉跟Oculus差不多,内置的东西都挺完善的.所以正常开发就可以了. zSpace有一套属于自己的Camera.Canvas.Mouse等(还是挺全的) 不过这里有一个坑: 1. ...
- Unity5 Survival Shooter开发笔记2
相机跟随人物移动 先介绍一个属性: public static float deltaTime; 这是一个只读的属性,返回上一帧到这一帧的时间.如果你想要在每一帧增加或者减少数据,需要用数据乘以del ...
最新文章
- pcDuino上如何安装wordpress
- 快速穷举TCP连接欺骗攻击-利用SYN Cookies
- 【Python】有效资源爬取并集
- 使用RxJava和SseEmitter进行服务器发送的事件
- 【UDP协议头解析】
- react.js app_如何创建Next.js入门程序以轻松引导新的React App
- Base64编码解码原理
- 源码分析参考:Dupefilter
- 虚拟云服务器 网站备案,云虚拟主机可以做备案吗
- CentOS配置服务开机自启
- 2021年国内四大 IoT 物联网平台选型对比综合评估报告
- 软件工程毕业设计题目推荐50例
- 【墨墨英语单词库免费开源无偿分享】小学、初中、高中、大学四六级专四专八、考研、托福、雅思等词书文本大合集
- Java根据模板导出PPT
- 『概率知识』伯努利试验及n重伯努利试验+方差协方差理解!
- 日历查询---在线阴阳历转换器
- shiro实现无状态的会话,带源码分析
- 微信小程序之首页轮播图片自适应高度
- Android 获得联系人并排序
- 金蝶KIS记账王光盘版 双12五折特惠
热门文章
- 长安汽车上半年净利大跌3成,却是三年来首次实质性盈利
- 编写代码时鼠标光标变成选择单个字符,而不是竖线,如何切换?
- css背景颜色占全部屏幕,css怎样让背景充满整个屏幕
- 海绵城市建设理念下市政道路的设计
- hybrid linux 显卡,Hybrid graphics (简体中文)
- html5基于canvas制作酷炫,应用HTML5 Canvas制作酷炫科技背景动画特效
- 生成对抗网络(Generative Adversarial Networks,GAN)
- lisp 焊缝标注_CAD在焊接图中的应用
- 零基础!!1小时学会跨时代的一门新语言 《建议收藏》
- 今天下班公交车上碰到的一件事