• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by $$anonymous$$ · Jul 01, 2013 at 04:24 AM · errorgametower-defense

What am i doing wrong in this code?

Hey guys, here is a script that ive written by following a tutorial, and the function ShowUpgradeGUI gives these errors Assets/Scripts/LevelMaster.js(181,10): BCE0044: expecting (, found 'ShowUpgradeGUI'. Assets/Scripts/LevelMaster.js(181,27): UCE0001: ';' expected. Insert a semicolon at the end. Assets/Scripts/LevelMaster.js(184,28): BCE0044: expecting :, found '='. I dont understand what Ive done wrong i wrote the code in the same fashion as other ones throughout the script but im not sure why it isnt working. If anyone could please help me out it would be appreciated greatly or even explain why it isnt working?

 #pragma strict
 
 //Global Variables
 static var playerDamage = 0;
 
 //States
 var waveActive : boolean = false;
 var spawnEnemies : boolean = false;
 var upgradePanelOpen : boolean = false;
 
 //Player Variables
 var healthCount : int = 10;
 var scoreCount : int = 0;
 var cashCount : int = 200;
 
 //Define Wave Specific Variables
 var waveLevel : int = 0;
 var difficultyMultiplier : float = 1;
 var waveLength : float = 30.0;
 var intermissionTime : float = 5.0;
 private var waveEndTime : float = 0;
 
 //Enemy Variables
 var enemyPrefabs : GameObject[];
 var flyerSpawns : Transform;
 private var flyerSpawnPoints : Transform[];
 var respawnMinBase : float = 3.0;
 var respawnMaxBase : float = 10.0;
 private var respawnMin : float = 3.0;
 private var respawnMax : float = 10.0;
 var respawnInterval : float = 2.5;
 var enemyCount : int = 0;
 private var lastSpawnTime : float = 0;
 
 //Turrets
 var turretCosts : int[];
 var onColor : Color;
 var offColor : Color;
 var allStructures : GameObject[];
 var buildBtnGraphics : UISlicedSprite[];
 var costTexts : UILabel[];
 private var structureIndex : int = 0;
 //
 
 // GUI Items
 
 //GUI Variables
 var waveText : UILabel;
 var healthText : UILabel;
 var scoreText : UILabel;
 var cashText : UILabel;
 var upgradeText : UILabel;
 var upgradeBtn : GameObject;
 
 //NGUI items
 var buildPanelOpen : boolean = false;
 var buildPanelTweener : TweenPosition;
 var buildPanelArrowTweener : TweenRotation;
 var upgradePanelTweener : TweenPosition;
 //
 
 //Placement plane items
 var placementPlanesRoot : Transform;
 var hoverMat : Material;
 var placementLayerMask : LayerMask;
 private var originalMat : Material;
 private var lastHitObj : GameObject;
 
 //Upgrade vars
 private var focusedPlane : PlacementPlane;
 private var structureToUpgrade : Turret_Base;
 private var upgradeStructure : GameObject;
 private var upgradeCost : int;
 //
 
 //--
 
 //called first thing on level start
 function Start ()
 {
     //reset the structure index, refresh the GUI
     structureIndex = 0;
     UpdateGUI();
 
     //Gather all the flyer spawn points into an array, so we dont have to do it manually
     flyerSpawnPoints = new Transform[flyerSpawns.childCount];
     var i : int = 0;
     for(var theSpawnPoint : Transform in flyerSpawns)
     {
         flyerSpawnPoints[i] = theSpawnPoint;
         i ++;
     }
     //
     
     //
     SetNextWave(); //setup the next wave variables (ie difficulty, respawn time, speed etc)
     StartNewWave(); //start the new wave
     //
 }
 //
 
 function Update ()
 {
     //--GUI
     if(buildPanelOpen)//if the build panel is open
     {
         //create a ray, and shoot it from the mouse position, forward into the game
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hit : RaycastHit;
         if(Physics.Raycast (ray, hit, 1000, placementLayerMask))
         {
             if(lastHitObj)//if we had prevously hit something
         {
             lastHitObj.renderer.material = originalMat;
         }
         
         lastHitObj = hit.collider.gameObject;
         originalMat = lastHitObj.renderer.material;
         lastHitObj.renderer.material = hoverMat;
     }
     else//if the raycast didnt hit anything
     {
         if(lastHitObj)//if we had previously hit something
         {
             lastHitObj.renderer.material = originalMat;//visually deselect that object
             lastHitObj = null;//nullify the plane selection this is so that we cant accidentally drop turrets without a proper and valid location selected
         }
     }
     
         //drop turrets on click
         if(Input.GetMouseButtonDown(0) && lastHitObj && !upgradePanelOpen)
         {
             focusedPlane = lastHitObj.GetComponent(PlacementPlane);
             if(focusedPlane.isOpen && turretCosts[structureIndex] <= cashCount)
             {
                 //drop the chosen structure exactly at the tiles position and rotation of zero
                 var newStructure : GameObject = Instantiate(allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity);
                 //set the new structure to have a random rotation. just for looks
                 newStructure.transform.localEulerAngles.y = (Random.Range(0,360));
                 //set the tiles tag to "taken" so we cant double place structures
                 focusedPlane.myStructure = newStructure;
                 focusedPlane.isOpen = false;
                 
                 cashCount -= turretCosts[structureIndex];
                 UpdateGUI();
             }
             else if(focusedPlane.myStructure != null)//if the plane already holds a turret
             {
                 ShowUpgradeGUI();
         }
     }
     
 //--GUI
     
 //Waves
 if(waveActive)
 {
     if(Time.time >= waveEndTime)
     {
         //Debug.Log("wave over");
         //stop spawning enemies
         spawnEnemies = false;
         //check for remaining enemies
         if(enemyCount == 0)
         {
                 FinishWave(); //end this wave
         }
     }
         
     if(spawnEnemies)
     {
         if(Time.time > (lastSpawnTime + respawnInterval))//wave is still going. spawn enemies
         {
             SpawnNewEnemy();
             }
         }
     }
 }
 
 //Upgrading Structures
 function ShowUpgradeGUI ()
 {
     //get the planes structure and that structures upgrade options
     structureToUpgrade = focusedPlane.myStructure.GetComponent(Turret_Base);
     upgradeStructure = structureToUpgrade.myUpgrade;
     
     //if the structure can be upgraded show menu
     if(upgradeStructure != null)
     {
         upgradePanelOpen = true;//first off set the state
         
         upgradeCost = structureToUpgrade.myUpgradeCost;//get the upgrade cost
         var upgradeName = structureToUpgrade.myUpgradeName;//get the upgrade name
         
         upgradeText.text = "Upgrade to" + upgradeName + "for $" + upgradeCost + "?";//set the text
         CostCheckButton(upgradeBtn, upgradeCost);//set the "confirm" button to active or not based on cost
         upgradePanelTweener.Play(true);//fly in the panel
     }
 }
 
 function ConfirmUpgrade()
 {
     var spawnPos = structureToUpgrade.transform.position;//get tower pos
     var spawnRot = structureToUpgrade.transform.rotation;//get tower rot
     Destroy(structureToUpgrade.gameObject);//destroy old tower
     var newStructure : GameObject = Instantiate(upgradeStructure, spawnPos, spawnRot);//spawn in new upgraded tower
     focusedPlane.myStructure = newStructure;
     
     cashCount -= upgradeCost;//subtract upgrade cost
     UpdateGUI();//update the GUI
     upgradePanelTweener.Play(false);//hide the upgrade panel
     upgradePanelOpen = false;//update the state
 }
 
 function CancelUpgrade()
 {
     upgradePanelTweener.Play(false);//hide the upgrade panel
     upgradePanelOpen = false;//update the state
 }
 //
     
 //end the wave
 function FinishWave ()
 {
     waveActive = false;
     
     //wait for it
     yield WaitForSeconds(intermissionTime);
     
     //on to the next
     SetNextWave();
     StartNewWave();
 }
 //
 
 //prepare for next wave
 function SetNextWave()
 {
     waveLevel ++;//up the wave level
     difficultyMultiplier = ((Mathf.Pow(waveLevel, .5)) * .25);//up the difficulty exponentially
     respawnMin = respawnMinBase * (1/difficultyMultiplier);//apply diff mult to respawn times (ie more unity)
     respawnMax = respawnMaxBase * (1/difficultyMultiplier);
 }
 //
 
 //start the new wave
 function StartNewWave ()
 {
     //Set the GUI
     UpdateGUI();
     
     //spawn the first enemy
     SpawnNewEnemy();
     
     //set the wave end time
     waveEndTime = Time.time + waveLength;
     
     //activate the wave
     waveActive = true;
     spawnEnemies = true;
 }
 //
 
 /*
 function SpawnFlyer()
 {
     nextFlyerSpawnTime += flyerInterval
     var i : int = Random.Range(0,flyerSpawnPoints,length);
     var newFlyer : GameObject = Instantiate(flyerPrefab, flyerSpawnPoints[i].position, flyerSpawnPoints[i].rotation);
 }
 */
 
 //spawn new enemies
 function SpawnNewEnemy()
 {
     //get a random index to choose an enemy prefab with
     var enemyChoice = Random.Range(0,enemyPrefabs.length);
     
     //since flying and ground units probably shouldnt in the same location, we have to seperate this part and spawn based on a tag
     var spawnChoice : int;
     if(enemyPrefabs[enemyChoice].tag == "FlyingEnemy")
     {
         //get a random index to choose spawn location with
         spawnChoice = Random.Range(0,flyerSpawnPoints.length);
         //spawn the flyer at a chosen location and rotation
         Instantiate(enemyPrefabs[enemyChoice], flyerSpawnPoints[spawnChoice].position, flyerSpawnPoints[spawnChoice].rotation);
     }
     else
     {
         //here we would choose a ground based spawn location
     }
     
     //let the game know we just added an enemy for keeping track of wave completion
     enemyCount ++;
     
     //set the current time as last spawntime
     lastSpawnTime = Time.time;
     
     //re-randomize the respawn interval
     respawnInterval = Random.Range(respawnMin, respawnMax);
 }
 //
 
 //--Custom Functions--//
 
 //this function will eventually contain all generic update events
 //this makes sure we dont have the same small parts being called over and over in different ways throughout the script
 
 function UpdateGUI ()
 {
     //Go through all structure buttons and set them to "off"
     for(var theBtnGraphic : UISlicedSprite in buildBtnGraphics)
     {
         theBtnGraphic.color = offColor;
     }
     //set the selected build button to "on"
     buildBtnGraphics[structureIndex].color = onColor;
     
     waveText.text = "Wave :" + waveLevel;
     scoreText.text = "Score :" + scoreCount;
     healthText.text = "Health :" + healthCount;
     cashText.text = "Cash :" + cashCount;
     
     CheckTurretCosts();
 }
 
 //called whenever a structure choice is clicked(the button in the build panel)
 function SetBuildChoice (btnObj : GameObject)
 {
     //when the buttons are clicked they send along their game object as a parameter which is caught by "btnObj" above
     //we then use that btnObj variable and get its name so we can easily check exactly which button was pressed
     var btnName : String = btnObj.name;
     
     //here we set an "index" based on which button was pressed
     //by doing this we can easily tell from anywhere in the script which structure is currently selected
     //also if we order things just right we can use this "index" to reference the correct array items automatically
     if(btnName == "Btn_Cannon")
     {
         structureIndex = 0;
     }
     else if(btnName == "Btn_Missile")
     {
         structureIndex = 1;
     }
     else if(btnName == "Btn_Mine")
     {
         structureIndex = 2;
     }
     
     //call this as a seperate function so that as things get more complicated all GUI can be updated at once in the same way
     UpdateGUI();
 }
                                                                 
 //Happens whenever the build panel arrow button is clicked                        
 function ToggleBuildPanel()
 {
     if(buildPanelOpen)//is the build panel already open
     {
         //hide all build tiles
         for(var thePlane : Transform in placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = false;
         }
         
          //fly out the build panel
         buildPanelTweener.Play (false);
         //rotate the build panel arrow
         buildPanelArrowTweener.Play (false);
         //mark the panel as "closed"
         buildPanelOpen = false;
     }
     else //...the build panel was closed, so instead to this...
     {    
         for(var thePlane : Transform in placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = true;
         }
         
         //fly in the build panel
         buildPanelTweener.Play (true);
         //rotate the build panel arrow
         buildPanelArrowTweener.Play (true);
         //mark the panel as "open"
         buildPanelOpen = true;
     }
 }
 
 //check to make sure we can purchase
 function CheckTurretCosts()
 {
     //iterate over all structure buttons
     for(var i : int = 0;i < allStructures.length; i++)
     {
         if(turretCosts[i] > cashCount)
     
         {
             costTexts[i].color = Color.red; //Set cost text to red color
             buildBtnGraphics[i].color = Color(.5,.5,.5,.5); //Set btn graphic to half alpha grey
             buildBtnGraphics[i].transform.parent.gameObject.collider.enabled = false; //disable this btn
         }
         else //we can afford this buttons turret
         {
             costTexts[i].color = Color.green; //set cost text to green color
         
             if(structureIndex == i) // is this button currently selected for placement 
                 buildBtnGraphics[i].color = onColor; //set the color to "on"
             else // this button is not currently selected
                 buildBtnGraphics[i].color = offColor; //set the color to "off"
             
             buildBtnGraphics[i].transform.parent.gameObject.collider.enabled = true; // enable this button
         }
     }
 }
 
 //Generic function to quickly check if we can afford an item and apply colors and settings to the items button
 function CostCheckButton(theBtn : GameObject, itemCost : int)
 {
     if(cashCount < itemCost)//we cant afford this item
     {
         theBtn.transform.Find("Label").gameObject.GetComponent(UILabel).color = Color.red;//set costs text to red color
         theBtn.transform.Find("Background").gameObject.GetComponent(UISprite).color = Color(.5,.5,.5,.5);//set btn graphic to half alpha grey
         theBtn.collider.enabled = false;//disable button collider
     }
     else//we can afford this item
     {
         theBtn.transform.Find("Label").gameObject.GetComponent(UILabel).color = Color.green;//set costs text to red color
         theBtn.transform.Find("Background").gameObject.GetComponent(UISprite).color = onColor;//set the color to on
         theBtn.collider.enabled = true;//disable button collider
     }
 }
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SinisterRainbow · Jul 01, 2013 at 05:31 AM

You are missing a bracket around line 110 in this code, aka, this code isn't closed:

 if(Physics.Raycast (ray, hit, 1000, placementLayerMask))

may be more than that, but that will solve some errors.

Comment

People who like this

0 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Jul 01, 2013 at 08:14 AM 0
Share

Cant believe I missed that, thankyou :)

avatar image SinisterRainbow · Jul 01, 2013 at 08:46 AM 0
Share

np, happens to everyone.. u'll know what the compiler is complaining about after doing this a few times (=

avatar image $$anonymous$$ · Jul 01, 2013 at 08:49 AM 0
Share

:) By the way have you ever coded with ngui before? Im trying to add a health bar to display enemy health

avatar image SinisterRainbow · Jul 01, 2013 at 09:10 AM 0
Share

no, i'm working on my own GL supported gui right now actually. But i'm sure someone can help

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Incremental game need help 1 Answer

Error... that I don't understand. 3 Answers

A node in a childnode? 1 Answer

unity not working help 2 Answers

Unity error CS1014 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges