- Home /
An another problem - Tower Defense GUI ver.2.
I didnt saw any action on my first post in this topic. Only 1 answer came which partly solved my problem. So I am reuploading my problem so maybe I have a better chance to fix this problem. My code is from a tutorial from unitycookie on youtube. It uses NGUI. In my case I am using Unity 4.0.7f pro and NGUI 2.6.4 full. I think its a mistyping error but it can be the version of NGUI or unity.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:
I really appriceate the help. Oh and here are some links:
UnityCookie TowerDefense Tutorial series:GoTo
The Video of the code (Part3B):GoTo
Answer by Jamora · Aug 15, 2013 at 04:57 AM
for(var theBtnGraphic : UISlicedSprite int buildBtnGraphics)
has int where it should say in
That'll at least change the first two errors...
Sorry but I have newer and newer problems:
I did everything that you said :(
You have the same typo in line 101, then lines 70-85 you need to have = ins$$anonymous$$d of :
You need to pay more attention to detail. Just keep working through the errors like this and eventually they'll end.
Ok now I have ton of problems solved but still I have Unexpected token : structureIndex 3 times: In:74,17 In:78,17 In:82,17
Do I need to change : to = there?
Those aren't syntax problems anymore, you need to read the error messages and fix the problem it tells you. the mystic numbers in parentheses are (row number, character where the error was encountered).
Those errors say a type can't be found (usually a class). You either have a typo in the name (RaycastHit is the correct spelling), you've not included the necessary namespaces or you need to create the type yourself. Reading error messages is part of program$$anonymous$$g, you have to learn at one point.