想要手柄控制就需要组件CrossPlatformInput
而这个组件需要Standard Assests资源包,我们可以在Assets Store里下载
使用把Profabs文件夹里的MobileSingleStickControl组件拖上去
(但是这里提示我无法删除这个组件,说是固定在这个上面的)
修改这里:
为Trump添加一个Rigidbody组件
取消重力
并且给它添加ControlTrump脚本
创建一个私有变量Rigidbody并在Start()函数中为其赋值
private Rigidbody rb;
赋值:
rb = GetComponent<Rigidbody>();
导入资源包:
using UnityStandardAssets.CrossPlatformInput;
void Update()
{
//x代表横向走,y代表纵向走
float x = CrossPlatformInputManager.GetAxis("Horizontal");
float y = CrossPlatformInputManager.GetAxis("Vertical");
//movement代表移动,我们这里是把二维的东西换到三维上,向上移动其实是z轴移动
Vector3 movement = new Vector3(x, 0, y);
rb.velocity = movement * 4f;
if (x!=0&&y!=0)
{
//这个是让人物旋转的
transform.eulerAngles = new Vector3(transform.eulerAngles.x, Mathf.Atan2(x, y) * Mathf.Rad2Deg, transform.eulerAngles.z);
}
}
下面是使用Animation使人物动画循环播放
walk动画也这么改
添加动画:同样的,先定义出来,再在Start()里面为其赋值,在Update()里面使用:
private Animation anim;
anim = GetComponent<Animation>();
if(x != 0 || y != 0)
{
anim.Play("walk");
}
else
{
anim.Play("idle");
}
从这里往下不用再写进PPT里了,从此单人Vuforia结束
还有一个小改进:
希望能为其添加音乐:
TRUMP VS. CLINTON - Songify 2016
添加对话:
https://blog.csdn.net/EmilyBluse/article/details/80586059
出现的问题:
Children of a Prefab instance cannot be deleted ormoved, and components cannot be reordered.
不能删除或移动Prefab实例的子实例,也不能重新排序组件。
You can open the Prefab in Prefab Mode torestructure the Prefab Asset itself, or unpack thePrefab instance to remove its Prefab connection.
重构Prefab资产本身,或解压缩Prefab实例以删除其Prefab连接。
解决办法:
参考:
(7)解除预制体关系Break Prefab Instance(Unpack Prefab)
Unpack Prefab :解除当前等级的Prefab绑定,不会对其嵌套的Prefab有影响
Unpack Prefab Completely :解除Prefab的所有绑定关系,包括其嵌套的Prefab