Пример #1
0
    public bool TestView(PowerObject powerObject)
    {
        //height check
        if (!powerObject.CanAbsorb(this))
        {
            return(false);
        }

        //reassignment lock
        if (absorbTarget == powerObject || absorbTarget == null)
        {
            absorbTarget = powerObject;
            if (timer > 1.0F)
            {
                if (absorbTarget.GetPower() > 0)
                {
                    powerObject.SetPower(powerObject.GetPower() - 1);
                    power++;
                    PlantTree();
                }
                else
                {
                    powerObject.Absorb();
                    absorbTarget = null;
                }
            }
            else
            {
                timer += Time.deltaTime;
            }
        }

        return(true);
    }
Пример #2
0
    //All items at places, whose base area is visible can be absorbed
    //aim at the base to absorb the object
    //Rocks can be absorbed without seeing the corresponding base area
    private void FireAbsorbRay()
    {
        if (!m_canAbsorb)
        {
            return;
        }

        RaycastHit hit;
        Ray        grabRay = new Ray(m_cameraTransform.position, m_cameraTransform.forward);

        Debug.DrawRay(m_cameraTransform.position, m_cameraTransform.forward * grabDistance);

        if (!Physics.Raycast(grabRay, out hit, grabDistance))
        {
            return;
        }

        PowerObject obj = null;

        switch (hit.collider.transform.root.tag)
        {
        case "Tree":
        case "Rock":
        case "Robot":
        case "Sentinel":
            obj = hit.collider.transform.root.gameObject.GetComponent <PowerObject>();
            break;

        case "Environment":
            obj = ObjectManager.instance.GetObjectAtPos(hit.point);
            break;
        }

        if (obj != null && (obj.GetType() == typeof(PO_Rock) || obj.CanAbsorb(this)))
        {
            power += obj.GetPower();
            obj.Absorb();
        }
    }