- Home /
An another problem - Tower Defense GUI (ver.3.)
I have a code from a tutorial on youtube (unitycookie). Somebody helped me to fix a lot of mystiping in the code but I som strange problems now that I think are related to NGUI. I am using Unity 4.0.7f pro and NGUI 2.6.4 full. Here is my 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 in 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 in placementPlanesRoot)
{
thePlane.gameObject.renderer.enabled = true;
}
buildPanelTweener.Play(true);
buildPanelArrowTweener.Play(true);
buildPanelOpen = true;
}
}
And the errors that are showing:
Please help! If this problem is related to NGUI what I need to do with the code to get it working.
Change your question's title to something more related to your question/errors. It doesn't really matter that it is for use with a towerdefense game..
If you didn't know what the errors mean you could just have set for example JS NGUI "does not denote a valid type" error.
If you did know what it meant you could have set "JS NGUI classes not found error"
Answer by InfiniBuzz · Aug 15, 2013 at 12:41 PM
HI
its
RaycastHit
not
RayCastHit
then you should read this: Using NGUI with javascript. The compiler does not know the classes you are trying to access like this (UISlicedSprite, TweenRotation, TweenPosition..). Maybe you also need to import AnimationOrTween;
- not sure
ltfb ;) hope it helps
I dont know what to import. I tried Animation and Tween but they dont work.
I fixed the problem completely. You need to put the script into the Assets folder. Thats a bug with NGUI.
Did you put the 4 folders int Plugins\NGUI\ like it says on the link provided by infiniBuzz?
You need to put the script into the Assets folder
Can you be more specific, so if someone else has this error, this can actually help him?
Your answer
Follow this Question
Related Questions
BCE0043: Unexpected token: }. 1 Answer
Detecting Webplayer's errors from Javascript 0 Answers
Raycast problems 2 Answers
What is wrong with my script? 1 Answer
BCE0044 Error - expecting :, found '=' 0 Answers