TowerDefence

Hi. :smile:
So i started with TowerDefence on youtube from CGCookie . And i got to the 3 part. But i need NGui, and i’m new to unity and not going to get serious in to it jet . NGui is i think 70e.
So my question is how can i make a turret place script without using NGUI just a regular GUI (TweenPosition and UISlicedSprite gives me problem .How to change that). I’m new to scripting and i don’t know much , so can someone help me?

Here’s the script from video.

var buildPanelOpen : boolean = false;
var buildPanelTweener : TweenPosition;
var buildPanelArrowTweener : TweenPosition;
//
	//Placement PlaneItems
var placementPlanesRoot : Transform;
var hovelMat : Material;
var placementLayerMask : LayerMask;
private var originalMat : Material;
private var lastHitObj : GameObject;

//builtselecteditems

var onColor : Color;
var offColor : Color;
var allStructures : GameObject[];
var buildBtnGraphics : UISlicedSprite[];
private var structuredIndex : int = 0;


function Start()
{
structuredIndex = 0;
UpdateGUI();
}

function Update(){

if(buildPanelOpen)
	{
      var ray : 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 = hovelMat;
	  }
	  
	  else 
	  {	
	  if(lastHitObj)
		{	
			lastHitObj.renderer.material = originalMat;
			lastHitObj = null;
		}
	  }
	  
	  if(Input.GetButtonDown (0)  lastHitObj)
	  {
		if(lastHitObj.tag ==" PlacementPlane_Open")
			{
				var newStructure : GameObject = Instantiate(allStructures[structuredIndex],lastHitObj.transform.position,Quaternion.identity);
				newStructure.transform.localEulerAngles.y = (Random.Range(0,360));
				lastHitObj.tag = "PlacementPlane_Taken";
				
			}
	  }
	}
}

function UpdateGUI()
{

for(var theBtnGraphic : UISlicedSprite in buildBtnGraphics)
	{
		theBtnGraphic.color = offColor;
	}
	buildBtnGraphics[structuredIndex].color = onColor;
}

function SetBuildChoice(btnObj : GameObject)
{

var btnName : String = btnObj.name;

if(btnName == "Btn_Cannon")
	{
	structuredIndex = 0;
	}
	else if(btnBName =="Btn_Missile")
	{
		structuredIndex = 1;
	}
	
UpdateGUI();


}

function ToggleBuildPanel()
{

	if(buildPanelOpen)
	{
		for(var thePlane : Transform in placementPlanesRoot)
		{
			thePlane.gameObject.renderer.enabled = false;
		}
			
		
	buildPanelTweener.Play(fasle);
	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;
	
	}

}

Thank you.

There’s a free ngui version available for learners. If you make the game just for fun or to get used to unity then the ngui watermark wont annoy you that much maybe.

Link:
http://forum.unity3d.com/threads/124032-NGUI-Free-Edition

And if you make a really good game which you want to release maybe you could sum up enough money for the full license :slight_smile: