Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by zalan23677632 · Aug 14, 2013 at 01:55 PM · errornguitower defense

An another problem - Tower Defense GUI

Sorry But I have an another problem in the same topic. I followed a tutorial on youtube which shows how to make a tower defense game in unity. But I stuck at the GUI part. This code is working with NGUI. I have Unity 4.0.7f and NGUI Full version 2.6.4. I don't know if it is a problem between the full or free version. So here is the code:

 #pragma strict
 
 var buildPanelOpen : boolean = false;
 var buildPanelTweener : TweenPosition;
 var buildPanelArrowTweener : TweenRotation;
 
 var placementPlanesRoot : Transform;
 var hoverMat : Material;
 private var originalMat : Material;
 private var lastHitObj : GameObject;
 
 var onColor : Color;
 var offColor : Color;
 var allStructures : GameObject[];
 var buildBtnGraphics : UISlicedSprite;
 private var structureIndex : int =0;
 
 function Start()
 {
     structureIndex = 0;
     UpdateGUI();
 }
 
 function Update ()
 {
     if(buildPanelOpen)
     {
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hit : RayCastHit;
         if(Physics.Raycast (ray, hit, 1000, placementLayerMask));
         {
             if(lastHitObj)
             {
                 lastHitObj.renderer.material = originalMat;
             }
             lastHitObj = hit.collider.gameObject;
             originalMat = lastHitObj.renderer.material;
             lastHitObj.renderer.material = hoverMat;
         }
         else
         {
             if(lastHitObj)
             {
                 lastHitObj.renderer.material = originalMat;
                 lastHitObj = null;
             }
         }
         if(Input.GetMouseButtonDown(0)&&lastHitObj)
         {
             if(lastHitObj.tag == "PlacementPlane_Open")
             {
                 var newStructure : GameObject = Instantiate(allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity;
                 newStructure.transform.localEulerAngles.y = (RandomRange(0,360));
                 lastHitObj.tag == "PlacementPlane_Taken";
             }
         }
     }
 }
 
 function UpdateGUI()
 {
     for(var theBtnGraphic : UISlicedSprite int buildBtnGraphics)
     {
         theBtnGraphic.color = offColor;
     }
     buildBtnGraphics[structureIndex].color = onColor;
 }
 
 function SetBuildChoice(btnObj : GameObject)
 {
     var btnName : String = btnObj.name;
     if(btnName == "Btn_Cannon")
     {
         structureIndex : 0;
     }
     else if(btnName == "Btn_Missile")
     {
         structureIndex : 1;
     }
     else if(btnName == "Btn_Mine")
     {
         structureIndex : 2;
     }
     UpdateGUI();
 }
 
 function ToggleBuildPanel()
 {
     if(buildPanelOpen)
     {
         for(var thePlane : Transform in placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = false;
         }
         buildPanelTweener.Play(false);
         buildPanelArrowTweener.Play(false);
         buildPanelOpen = false;
     }
     else
     {
         for(var thePlane : Transform int placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = true;
         }
         buildPanelTweener.Play(true);
         buildPanelArrowTweener.Play(true);
         buildPanelOpen = true;
     }
 }

And here are the problems that unity shows for me: alt text

THX and If you can help me than please write it down. Also the series is from UnityCookies (on youtube) and the part that the code is in it is part 3B.

error_ngui_td.jpg (401.6 kB)
Comment
Add comment
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
0

Answer by Joyrider · Aug 14, 2013 at 01:56 PM

Remove the semicolon at the end of your if-statement line 30

Comment
Add comment · Show 2 · 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 zalan23677632 · Aug 14, 2013 at 04:00 PM 0
Share

It solve some problems but now I have some other errors:alt text

error_ngui_td2.jpg (480.3 kB)
avatar image zalan23677632 · Aug 14, 2013 at 04:04 PM 0
Share

Also the Code reuploaded becouse I fixed som other errors: #pragma strict

 var buildPanelOpen : boolean = false;
 var buildPanelTweener : TweenPosition;
 var buildPanelArrowTweener : TweenRotation;
 
 var placementPlanesRoot : Transform;
 var hover$$anonymous$$at : $$anonymous$$aterial;
 private var original$$anonymous$$at : $$anonymous$$aterial;
 private var lastHitObj : GameObject;
 
 var onColor : Color;
 var offColor : Color;
 var allStructures : GameObject[];
 var buildBtnGraphics : UISlicedSprite;
 private var structureIndex : int =0;
 
 function Start()
 {
     structureIndex = 0;
     UpdateGUI();
 }
 
 function Update ()
 {
     if(buildPanelOpen)
     {
         var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
         var hit : RayCastHit;
         if(Physics.Raycast (ray, hit, 1000, placementLayer$$anonymous$$ask))
         {
             if(lastHitObj)
             {
                 lastHitObj.renderer.material = original$$anonymous$$at;
             }
             lastHitObj = hit.collider.gameObject;
             original$$anonymous$$at = lastHitObj.renderer.material;
             lastHitObj.renderer.material = hover$$anonymous$$at;
         }
         else
         {
             if(lastHitObj)
             {
                 lastHitObj.renderer.material = original$$anonymous$$at;
                 lastHitObj = null;
             }
         }
         if(Input.Get$$anonymous$$ouseButtonDown(0)&&lastHitObj)
         {
             if(lastHitObj.tag == "PlacementPlane_Open")
             {
                 var newStructure : GameObject = Instantiate(allStructures[structureIndex], lastHitObj.transform.position, Quaternion.identity);
                 newStructure.transform.localEulerAngles.y = (RandomRange(0,360));
                 lastHitObj.tag == "PlacementPlane_Taken";
             }
         }
     }
 }
 
 function UpdateGUI()
 {
     for(var theBtnGraphic : UISlicedSprite int buildBtnGraphics)
     {
         theBtnGraphic.color = offColor;
     }
     buildBtnGraphics[structureIndex].color = onColor;
 }
 
 function SetBuildChoice(btnObj : GameObject)
 {
     var btnName : String = btnObj.name;
     if(btnName == "Btn_Cannon")
     {
         structureIndex : 0;
     }
     else if(btnName == "Btn_$$anonymous$$issile")
     {
         structureIndex : 1;
     }
     else if(btnName == "Btn_$$anonymous$$ine")
     {
         structureIndex : 2;
     }
     UpdateGUI();
 }
 
 function ToggleBuildPanel()
 {
     if(buildPanelOpen)
     {
         for(var thePlane : Transform in placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = false;
         }
         buildPanelTweener.Play(false);
         buildPanelArrowTweener.Play(false);
         buildPanelOpen = false;
     }
     else
     {
         for(var thePlane : Transform int placementPlanesRoot)
         {
             thePlane.gameObject.renderer.enabled = true;
         }
         buildPanelTweener.Play(true);
         buildPanelArrowTweener.Play(true);
         buildPanelOpen = true;
     }
 }

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.

Follow this Question

Answers Answers and Comments

16 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 avatar image

Related Questions

An another problem - Tower Defense GUI ver.2. 1 Answer

Contunuing from old scene 1 Answer

Unity 3.4.0 Running really slow 1 Answer

Problem with SSL CA cert 0 Answers

problem in working with project 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