Esempio n. 1
0
    public void Absorb()
    {
        ray.origin    = new Vector3(transform.position.x, transform.position.y, -0.2f);
        ray.direction = new Vector3(0, 0, 1);
        hits          = Physics.SphereCastAll(ray, 0.45f, 2);

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject.GetComponent <GrowthBase>())
            {
                GrowthBase currentBlob = hit.transform.gameObject.GetComponent <GrowthBase>();
                if (lastBlob != null)
                {
                    if (lastBlob.currentGrowth > currentBlob.currentGrowth)
                    {
                        lastBlob.currentGrowth += currentBlob.currentGrowth;
                        Destroy(currentBlob.gameObject);
                    }
                    else
                    {
                        currentBlob.currentGrowth += lastBlob.currentGrowth;
                        Destroy(lastBlob.gameObject);
                        lastBlob = currentBlob;
                    }
                }
                else
                {
                    lastBlob = currentBlob;
                }
            }
        }
        lastBlob = null;
    }
Esempio n. 2
0
    public void SwapGrowth()
    {
        float temp;

        temp = selectedGrowth.currentGrowth;
        Destroy(selectedGrowth);

        selectedGrowth = selectedGrowth.gameObject.AddComponent <GrowthTower>();
        selectedGrowth.currentGrowth = temp;
    }
Esempio n. 3
0
    void Update()
    {
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Input.GetMouseButtonDown(0) || Input.GetTouch(0).phase == TouchPhase.Began)
        {
            if (Physics.Raycast(ray, out hit, 20))
            {
                if (hit.transform.gameObject.name == "Void")
                {
                    prevPoint = hit.point;
                    toScroll  = true;
                }

                if (hit.transform.gameObject.GetComponent <GrowthBase>())
                {
                    toScroll                        = false;
                    selectedGrowth                  = hit.transform.gameObject.GetComponent <GrowthBase>();
                    blobMovementPivot.position      = hit.point;
                    selectedGrowth.transform.parent = blobMovementPivot.transform;
                }
            }
        }

        if (Input.GetMouseButton(0) || Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            RaycastHit anchorPoint;
            if (Physics.Raycast(ray, out anchorPoint, 20))
            {
                if (toScroll)
                {
                    transform.position -= (anchorPoint.point - prevPoint);
                    prevPoint           = anchorPoint.point;
                }
                else
                {
                    blobMovementPivot.position = anchorPoint.point;
                    blobMovementPivot.position = new Vector3(blobMovementPivot.position.x, blobMovementPivot.position.y, -0.2f);
                }
            }
        }

        if (Input.GetMouseButtonUp(0) || Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            if (!toScroll)
            {
                selectedGrowth.transform.parent = null;
                selectedGrowth.Absorb();
            }
        }
    }
Esempio n. 4
0
 void Start()
 {
     firstGrowth.currentGrowth = PlayerData.DataCheck();
     selectedGrowth            = firstGrowth;
     blobMovementPivot         = GameObject.Find("SelectedObjectPivot").transform;
 }