Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        script    = FindObjectOfType(typeof(GroundCreation)) as GroundCreation;
        gamePlane = script.groundArray;

        transform.position = gamePlane[x + y * 30].transform.position;
        GameObject.FindGameObjectWithTag("GameController").GetComponent <PlayPauseStepControll>().AddEnemy(this.gameObject);
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Creating)
        {
            // Ensure its moving if we haven't released it yet
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform != transform)
                {
                    Vector3 derp   = hit.transform.position - Camera.main.transform.position;
                    Vector3 newPos = hit.transform.position - derp.normalized;
                    transform.position = newPos;
                }
            }

            else
            {
                transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x
                                                                                , Input.mousePosition.y, 10));
            }
            // Check if we've released
            if (Input.GetMouseButtonDown(0))
            {
                Creating = false;
            }
        }
        else
        {
            // Always use own values
            EntitiesList entityList = GameObject.FindGameObjectWithTag("Entities").GetComponent <EntitiesList>();

            bool foundSelected = false;
            bool isUs          = false;

            foreach (var item in entityList.actors)
            {
                foundSelected = item.GetComponent <EntityHolder>().selected;
                if (foundSelected)
                {
                    if (item.GetComponent <EntityHolder>().GetActor() == gameObject)
                    {
                        isUs = true;
                    }
                    break;
                }
            }


            if (useNormalShape)
            {
                // Update the ground cubes
                Vector3      thisPosition = transform.position;
                GameObject[] ground       = GameObject.FindGameObjectsWithTag("Respawn");
                foreach (GameObject cube in ground)
                {
                    Vector3 cubePosition = cube.transform.position;
                    float   distance     = (cubePosition - thisPosition).magnitude;
                    float   charge       = chargeValue / distance;

                    if (foundSelected)
                    {
                        if (isUs)
                        {
                            cube.GetComponent <PotentialFieldCharge>().AddCharge(charge);
                        }
                        else
                        {
                            cube.GetComponent <PotentialFieldCharge>().AddUnselectedCharge(charge);
                        }
                    }
                    else
                    {
                        cube.GetComponent <PotentialFieldCharge>().AddCharge(charge);
                    }
                    //cube.GetComponent<PotentialFieldCharge>().AddCharge(charge);
                }
            }
            else
            {
                GameObject     gridCreator    = GameObject.FindGameObjectWithTag("GridCreator");
                GroundCreation groundCreation = gridCreator.GetComponent <GroundCreation>();
                //groundCreation.groundArray;
                int gridX = (int)transform.position.x;
                int gridY = (int)transform.position.y;

                // Start stop cause field can be larger then grid
                int startX = Mathf.Max(gridX - 15, 0);
                int startY = Mathf.Max(gridY - 15, 0);
                int endX   = Mathf.Min(gridX + 15, 30);
                int endY   = Mathf.Min(gridY + 15, 30);

                // Only loop over grid
                for (int y = 0; y < 30; y++)
                {
                    for (int x = 0; x < 30; x++)
                    {
                        float chargeToAdd = customField[y * 30 + x];

                        if (foundSelected)
                        {
                            if (isUs)
                            {
                                groundCreation.groundArray[y * 30 + x].GetComponent <PotentialFieldCharge>().AddCharge(chargeToAdd);
                            }
                            else
                            {
                                groundCreation.groundArray[y * 30 + x].GetComponent <PotentialFieldCharge>().AddUnselectedCharge(chargeToAdd);
                            }
                        }
                        else
                        {
                            groundCreation.groundArray[y * 30 + x].GetComponent <PotentialFieldCharge>().AddCharge(chargeToAdd);
                        }

                        //groundCreation.groundArray[y * 30 + x].GetComponent<PotentialFieldCharge>().AddCharge(chargeToAdd);
                    }
                }
            }
        }
    }