Ejemplo n.º 1
0
        // Update is called once per frame
        void Update()
        {
            GenerateInstances();

            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(mouseRay, out hit, 1000f, layerMask, QueryTriggerInteraction.Ignore))
            {
                Placeable p = hit.transform.GetComponent <Placeable>();

                if (p && p.isPlaced == false)
                {
                    GameObject gHologram = hologram.gameObject;
                    GameObject gTower    = tower.gameObject;

                    if (gHologram.activeSelf == false)
                    {
                        gHologram.SetActive(true);
                    }

                    GameObject instance = instances[currentTower];

                    instance.transform.position = p.transform.position;

                    if (Input.GetMouseButtonDown(0))
                    {
                        p.isPlaced = true;

                        gHologram.SetActive(false);
                        gTower.SetActive(true);

                        instance.transform.SetParent(p.transform);
                        instances[currentTower] = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void Update()
        {
            DisableAllHolograms();

            // Perform raycast from mouse position
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(mouseRay, out hit))
            {
                // Is the hit a placeable AND is it available?
                Placeable p = hit.transform.GetComponent <Placeable>();
                if (p && p.isAvailable)
                {
                    // Get current hologram (tower)
                    GameObject hologram = holograms[currentTower];
                    // Activate hologram
                    hologram.SetActive(true);
                    // Position hologram
                    hologram.transform.position = p.transform.position;

                    // Is left mouse button down?
                    if (Input.GetMouseButtonDown(0))
                    {
                        // Get current tower prefab
                        GameObject towerPrefab = towers[currentTower];

                        // Spawn tower there
                        Instantiate(towerPrefab, p.GetPivotPoint(), p.transform.rotation, transform);

                        // Spot is no longer available
                        p.isAvailable = false;
                    }
                }
            }
        }