Esempio n. 1
0
    //triggered when pressing space bar (via PlayerControl)
    public void Interact()
    {
        if (HeldItem != null)
        {
            ThrowItem();
        }
        else
        {
            Collider[] nearbyObjects = Physics.OverlapSphere(transform.position, 2, interactLM);//check surroundings for stuff
            if (nearbyObjects.Length > 0)
            {
                GameObject closest = Tools.FindClosestColliderInGroup(nearbyObjects, transform.position);
                if (closest != null)
                {
                    Target = closest;

                    ITargettable oldTarget = Target.GetComponent <ITargettable>();
                    if (oldTarget != null)
                    {
                        oldTarget.NotTargeted();
                    }
                    //SetTarget(closest);
                }
                //Target = nearbyObjects[0].gameObject;//i only use the first object of an array which I believe is random, but that's fine I think?
                MeleeAttack();
            }
            else
            {
                if (bobHeight < 1.3f)
                {
                    Swing(2);//2 will show a red trail streak to indicate pw0ness
                }
                else
                {
                    Swing();
                }
            }
        }
    }
Esempio n. 2
0
    //used to target (set "ownership") of items so multiple agents don't go for same thing
    public void SetTarget(GameObject targetedObj)
    {
        if (!enemy)
        {
            if (Target != null)
            {
                ITargettable oldTarget = Target.GetComponent <ITargettable>();
                if (oldTarget != null)
                {
                    oldTarget.NotTargeted();
                }
            }
        }

        Target = targetedObj;
        if (!enemy)
        {
            ITargettable newTarget = Target.GetComponent <ITargettable>();
            if (newTarget != null)
            {
                newTarget.Targeted(gameObject);
            }
        }
    }