AR Trump

想要手柄控制就需要组件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);
        }
    }

介绍:Transform.eulerAngles

下面是使用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)

Unity2018.3 笔记 ——prefab解除绑定

Unpack Prefab :解除当前等级的Prefab绑定,不会对其嵌套的Prefab有影响
Unpack Prefab Completely :解除Prefab的所有绑定关系,包括其嵌套的Prefab

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值