Example #1
0
 public void PickUpItem(InteractionScript script)
 {
     if (script.m_canPick)
     {
         m_carryItem = script;
         m_carryItem.PickUpItem(m_pickNode.transform);
         m_interactionItems.Remove(m_carryItem);
     }
 }
Example #2
0
    public void Update()
    {
        if (!m_canInput)
        {
            return;
        }

        m_movement.x = Input.GetAxisRaw("Horizontal");
        //m_movement.y = Input.GetAxisRaw("Vertical");

        if (m_movement == Vector2.zero)
        {
            string animName = m_carryItem != null ? "Pick_Idle" : "Idle";
            m_footAudio.Stop();
            PlayAnimation(animName, m_movement.x, m_recordY);
        }
        else
        {
            m_recordY = m_movement.y;
            if (!m_footAudio.isPlaying)
            {
                m_footAudio.Play();
            }
            string animName = m_carryItem != null ? "Pick_Walk" : "Walk";
            PlayAnimation(animName, m_movement.x, m_recordY);
        }

        if (m_interactionItems.Count > 0)
        {
            //交互
            if (Input.GetKeyDown(KeyCode.Space))
            {
                for (int i = 0; i < m_interactionItems.Count; i++)
                {
                    bool result = m_interactionItems[i].TriggerEnterAction();
                    if (result)
                    {
                        return;
                    }
                }
                return;
            }

            if (m_carryItem == null)
            {
                float             distance = float.MaxValue;
                InteractionScript item     = null;
                if (Input.GetKeyDown(KeyCode.E))
                {
                    for (int i = 0; i < m_interactionItems.Count; i++)
                    {
                        //捡起、放下
                        if (m_interactionItems[i].m_canPick)
                        {
                            float dis = Vector2.Distance(transform.position, m_interactionItems[i].transform.position);
                            if (dis < distance)
                            {
                                distance = dis;
                                item     = m_interactionItems[i];
                            }
                        }
                    }

                    if (item != null)
                    {
                        m_carryItem = item;
                        m_carryItem.PickUpItem(m_pickNode.transform);
                        m_interactionItems.Remove(m_carryItem);
                    }

                    return;
                }
            }
        }

        if (m_carryItem != null && Input.GetKeyDown(KeyCode.E))
        {
            m_carryItem.DropDownItem(transform);
            m_carryItem = null;
        }
    }