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][1]
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.
[1]: /storage/temp/14288-error_ngui_td.jpg
↧