puppet-master道具篇

先准备一批道具模型 链接: https://pan.baidu.com/s/1mq9HYDEazUKsN0BP-lD7Bw?pwd=184i 提取码: 184i

  • 场景中新建空对象命名Prop->新建子对象命名Mesh Root
  • 将道具预制体Ham拖入Prop/Prop/Mesh Root
  • Prop/Mesh Root下的Ham只保留Mesh组件如下
  • Prop下的Ham只保留Collider组件如下

  • Prop上添加如下组件

  1. Rigidbody默认值
  2. Collider这里我选择的Mesh Collider ,Mesh属性选择HamMeshConvex选择true
  3. Puppet Master PropMesh Root选择Prop下的·Mesh Root 如下
  • 对象结构如下

如何拾取道具

如上结构添加一个Pick Up Trigger

脚本的逻辑

using UnityEngine;
using System.Collections;
using RootMotion.Dynamics;


    public class PropPickUpTrigger : MonoBehaviour {
        // 用户的道具
        public PuppetMasterProp prop;
        // 左手
        private PropMuscle propMuscleRight;
        private bool isPickUp;
        public Transform Player;
        /**
         * 判断拿武器的人是否死亡
         */
        private void Update()
        {

            if (Player)
            {
                Redirector redirector = Player.GetComponent<Redirector>();
                if(redirector.hitController.IsDead)
                {
                    if (connectTo&&connectTo.currentProp)
                    {
                        connectTo.currentProp = null;
                    }
                    
                    Player = null;
                    isPickUp = false;
                    redirector.isProp = false;
                };
            }
            else
            {
                Player = null;
                isPickUp = false;
            }
        }
        void OnTriggerEnter(Collider collider)
        {
            Debug.Log("有碰到武器"+isPickUp);
            if (isPickUp) return;
            // 如果是人
            Transform player = collider.transform.root;
            Transform puppetMaster = player.Find("PuppetMaster");
            if (puppetMaster)
            {
                Redirector redirector = player.GetComponent<Redirector>();
                if(redirector.hitController.IsDead)return;
                if (redirector.isProp) return;
                Player = player;
                propMuscleRight = puppetMaster
                    .Find("Prop Muscle RightForearm_end")
                    .GetComponent<PropMuscle>();
                connectTo.currentProp = prop;
                redirector.isProp = true;
                isPickUp = true;
            }
        }
        private PropMuscle connectTo {
            get {
                return  propMuscleRight;
            }
        }
    }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

拾取核心逻辑是

// 判断是不是与人发生碰撞
// 判断道具状态 (如是否已被拾取)。。。
// 判断人物状态 (是否死亡,是否已有武器) 。。。
// 获取人物的`Prop Muscle`插槽
// 设置`Prop Muscle`插槽的`currentProp`属性
// 设置人物和道具的状态
1
2
3
4
5
6