Пример #1
0
    // Use this for initialization
    void Start()
    {
        GameObject[] arrows = Resources.LoadAll <GameObject>(path);

        GameObject[] intersections = GameObject.FindGameObjectsWithTag("I");
        foreach (GameObject i in intersections)
        {
            Intersection inter = i.AddComponent <Intersection>();

            for (int count = 0; count < i.transform.childCount; count++)
            {
                GameObject child = i.transform.GetChild(count).gameObject;
                child.AddComponent <Arrow>();
                //child.AddComponent<PolygonCollider2D>();

                if (child.name == dirs.NE.ToString())
                {
                    GameObject a = Instantiate(arrows[0], child.transform);
                    a.transform.localPosition = Vector3.zero;
                    a.transform.localScale    = a.transform.localScale.normalized * 3;
                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.NW.ToString())
                {
                    GameObject a = Instantiate(arrows[1], child.transform);
                    a.transform.localPosition = Vector3.zero;
                    a.transform.localScale    = Vector3.one * 3;
                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.SE.ToString())
                {
                    GameObject a = Instantiate(arrows[2], child.transform);
                    a.transform.localPosition = Vector3.zero;
                    a.transform.localScale    = Vector3.one * 3;
                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.SW.ToString())
                {
                    GameObject a = Instantiate(arrows[3], child.transform);
                    a.transform.localPosition = Vector3.zero;
                    a.transform.localScale    = Vector3.one * 3;
                    a.SetActive(false);
                    inter.AddArrow(a);
                }
            }
        }
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        //En vez de añadir el script Arrow a la baldosa de la intersección añadimos únicamente el prefab
        //Este prefab ya tendrá el script Arrow

        GameObject arrow = Resources.Load <GameObject>(path + "/General_Arrow");


        GameObject[] intersections = GameObject.FindGameObjectsWithTag("I");
        foreach (GameObject i in intersections)
        {
            Intersection inter = i.AddComponent <Intersection>();

            for (int count = 0; count < i.transform.childCount; count++)
            {
                GameObject child = i.transform.GetChild(count).gameObject;

                //No incluimos el script Arrow a las baldosas
                child.AddComponent <Arrow>();

                //Ahora incluimos otro script que comprueba si una flecha ha sido pulsada

                if (child.name == dirs.NE.ToString())
                {
                    GameObject a = Instantiate(arrow, child.transform);
                    a.transform.localPosition = Vector3.zero;
                    //Rotación

                    a.transform.rotation = Quaternion.Euler(180, 0, 0);

                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.NW.ToString())
                {
                    GameObject a = Instantiate(arrow, child.transform);
                    a.transform.localPosition = Vector3.zero;
                    //Rotación

                    a.transform.rotation = Quaternion.Euler(180, 180, 0);


                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.SE.ToString())
                {
                    GameObject a = Instantiate(arrow, child.transform);
                    a.transform.localPosition = Vector3.zero;
                    a.transform.rotation      = Quaternion.Euler(0, 0, 0);
                    a.SetActive(false);
                    inter.AddArrow(a);
                }
                else if (child.name == dirs.SW.ToString())
                {
                    GameObject a = Instantiate(arrow, child.transform);
                    a.transform.localPosition = Vector3.zero;
                    //Rotación

                    a.transform.rotation = Quaternion.Euler(0, 180, 0);

                    a.SetActive(false);
                    inter.AddArrow(a);
                }
            }
        }
    }