Example #1
0
    // Update is called once per frame
    void Update()
    {
        //disable all holograms at start
        DisableAllHolograms();

        //fire a raycast from camera to the mouse position
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //perform raycast
        if (Physics.Raycast(mouseRay, out hit))
        {
            //get the placeable script
            Placeable p = hit.transform.GetComponent <Placeable>();

            if (p && p.isAvailable)
            {
                //get hologram of current tower
                GameObject hologram = holograms[currentIndex];
                hologram.SetActive(true);
                //set position of hologram
                hologram.transform.position = p.GetPivotPoint();
            }
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        //Disable all Holgrams at the start of the frame
        DisableAllHolograms();


        if (Time.timeScale == 1)
        {
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            //Perform Raycast
            if (Physics.Raycast(mouseRay, out hit))
            {
                //Try getting a placeable script
                Placeable p = hit.transform.GetComponent <Placeable>();
                // if it is a placeable and its available (no tower spwawned)
                if (p && p.isAvailable)
                {
                    //tower cost available
                    if (money >= towers[currentIndex].GetComponent <Tower>().cost)
                    {
                        //Get position of placeable
                        Vector3 placeablePoint = p.transform.position;
                        //Get hologram of current tower
                        GameObject hologram = holograms[currentIndex];
                        hologram.SetActive(true);
                        //set position of hologram
                        hologram.transform.position = p.GetPivotPoint();

                        if (Input.GetMouseButtonDown(0))
                        {
                            // Get the prefab
                            GameObject towerPrefab = towers[currentIndex];
                            //spawn the tower
                            GameObject tower = Instantiate(towerPrefab);
                            //position to placeable
                            tower.transform.position = p.GetPivotPoint();
                            // The tile is no longer available
                            p.isAvailable = false;
                            money         = money - towers[currentIndex].GetComponent <Tower>().cost;
                            UpdateMoney();
                        }
                    }
                }
            }
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        //Disable all holograms at the start of each frame
        DisableAllHolograms();

        //Creates a ray
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        //Performing raycast here
        if (Physics.Raycast(mouseRay, out hit))
        {
            //try to get placeable from thing we hit
            Placeable p = hit.collider.GetComponent <Placeable>();
            //is it placeable?...AND placeable is Available
            if (p && p.isAvailable)
            {
                //Set placeable point for testing
                //placeablePoint = p.transform.position;
                //>>HOVER MECHANIC<<
                //Get hologram of current tower
                GameObject hologram = holograms[currentTower];
                //Activate hologram
                hologram.SetActive(true);
                //position hologram to tile
                hologram.transform.position = p.GetPivotPoint();

                //>>PLACEMENT MECHANIC<<
                //if left mouse is down
                if (Input.GetMouseButtonDown(0))
                {
                    if (WaveSpawner.money >= towerCost)
                    {//get the current tower prefab
                        GameObject towerPrefab = towers[currentTower];
                        //spawn a new tower
                        GameObject tower = Instantiate(towerPrefab, towerParent);
                        //position new tower to tile
                        tower.transform.position = p.GetPivotPoint();
                        //tile is no longer placeable
                        p.isAvailable      = false;
                        WaveSpawner.money -= towerCost;
                    }
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        currentHologram.SetActive(false);
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); // Create ray from mouse position on Camera
        RaycastHit hit;

        if (Physics.Raycast(mouseRay, out hit, rayDistance, hitLayers, triggerInteraction)) // Perform Raycast
        {
            //Debug.Log("kablah");
            Placeable p = hit.transform.GetComponent <Placeable>(); // Try getting Placeable script
            if (p && p.isAvailable)                                 // If it is a placeable AND it's available (no tower spawned)
            {
                bool canPurchase;
                if (pr.currency >= selectedTower.cost)
                {
                    canPurchase = true;
                }
                else
                {
                    canPurchase = false;
                }

                currentHologram.SetActive(true);
                currentHologram.transform.position = p.GetPivotPoint(); // Set position of hologram to pivot point (if any)

                if (canPurchase)
                {
                    //currentHologram.GetComponent<Material>().color = canPlace;

                    // If Left mouse is down
                    if (Input.GetMouseButtonDown(0))
                    {
                        GameObject tower = Instantiate(selectedTower.tower); // Instantiates tower
                        tower.transform.position = p.GetPivotPoint();        // Position to placeable
                        p.isAvailable            = false;                    // The Tile is no longer available
                        pr.currency -= selectedTower.cost;                   // Subtracts appropriate cost from available currency
                    }
                }
                else
                {
                    //currentHologram.GetComponent<Material>().color = cannotPlace;
                }
            }
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        // Disable all holograms at the start of each frame
        DisableAllHolograms();
        // Creates a ray
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        // Performing Raycast here
        if (Physics.Raycast(mouseRay, out hit))
        {
            // Try to get Placeable from thing we hit
            Placeable p = hit.collider.GetComponent <Placeable>();
            // Is it placable? ... AND placeable is Available
            if (p && p.isAvailable)
            {
                //>>Hover Mechanic<<
                // Get hologram of current tower
                GameObject hologram = holograms[currentTower];
                // Activate hologram
                hologram.SetActive(true);
                // Position hologram to tile
                hologram.transform.position = p.GetPivotPoint();

                //>>Placement Mechanic<<
                // If left mouse is down
                if (Input.GetMouseButtonDown(0))
                {
                    // Get the current tower prefab
                    GameObject towerPrefab = towers[currentTower];
                    // Spawn a new tower
                    GameObject tower = Instantiate(towerPrefab, towerParent);
                    // Position new tower to tile
                    tower.transform.position = p.GetPivotPoint();
                    // Placeable is not available anymore
                    p.isAvailable = false;
                }
            }
        }
    }
Example #6
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[0];
                // Activate hologram
                hologram.SetActive(true);
                // Position hologram
                hologram.transform.position = p.transform.position;

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

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

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

                    Shop.money -= towerPrice;
                }
                //if (Input.GetMouseButtonDown(1) && Shop.money >= towerPrice)
                //{
                // Get current tower prefab
                // GameObject towerPrefab = towers[1];

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

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

                // Shop.money -= towerPrice;

                //}
            }
        }
    }
Example #7
0
    // Update is called once per frame
    void Update()
    {
        // Disable all Holograms at the start of the frame
        DisableAllHolograms();

        // Create ray from mouse position on Camera
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        // Perform Raycast
        if (Physics.Raycast(mouseRay, out hit, rayDistance, hitLayers, triggerInteraction))
        {
            Debug.Log("kablah");
            // Try getting Placeable script
            Placeable p = hit.transform.GetComponent <Placeable>();
            // If it is a placeable AND it's available (no tower spawned)
            if (p && p.isAvailable)
            {
                // Get hologram of current tower
                GameObject hologram = holograms[currentIndex];
                hologram.SetActive(true);
                // Set position of hologram to pivot point (if any)
                hologram.transform.position = p.GetPivotPoint();

                // If Left mouse is down
                if (Input.GetMouseButtonDown(0))
                {
                    // Get the prefab
                    GameObject towerPrefab = towers[currentIndex];
                    // Spawn the tower
                    GameObject tower = Instantiate(towerPrefab);
                    // Position to placeable
                    tower.transform.position = p.GetPivotPoint();
                    // The Tile is no longer available
                    p.isAvailable = false;
                }
            }
        }
    }
Example #8
0
    void Update()
    {
        Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(mouseRay, out hit))
        {
            Placeable p = hit.collider.GetComponent <Placeable>();
            if (p && p.isAvaliable)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    GameObject towerPrefab = towers[currentTower];
                    GameObject tower       = Instantiate(towerPrefab, towerParent);
                    tower.transform.position = p.GetPivotPoint();
                    p.isAvaliable            = false;
                }
            }
        }
    }