- Home /
help with tower defense
ok so heres the problem I have script that lets you buy towers and place them on the ground it has an amount of money left and the tower cost in it, however I need those to show up on the screen as gui and I am stuck! also there is a message that if the tower price in greater than the amount of money left it will show up in the debug console how can I get it to show up as a message on screen aswell.
thanks in advance
Have you had any experience with the unity's GUI?
just so i know what level my answer should be at :P
Answer by matt.weeden · Dec 09, 2011 at 01:53 AM
var TowerPrefab : Transform;
var totalMoney = 3000;
var towerPrice = 900;
function Update () {
if(Input.GetButtonDown("Fire1"))
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray, hit) && towerPrice <= totalMoney)
Instantiate(TowerPrefab, hit.point, Quaternion.identity);
if(Physics.Raycast(ray, hit) && towerPrice <= totalMoney)
totalMoney = totalMoney - towerPrice;
if(towerPrice >= totalMoney)Debug.Log("insufficient funds");
}
}
Answer by bula · Dec 08, 2011 at 10:58 PM
Lol thats s easy (if i undestanded) If you want something like a menu for buying towers is easy....Make the menu in photoshop Fireworks whatever and add a gui texture in the game Make the scipt so that if you press it is actually hapening something.... And then there is your Buy Towers Menu.
if you want something like the script you will can find it at Unity stundents Gui thingy Ok Hope it Helps :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Setting Scroll View Width GUILayout 1 Answer
gui help for ammo display 1 Answer
Pause Menu 5 Answers
Floating Enemy Health Bars? 1 Answer