Exemplo n.º 1
0
	// Update is called once per frame
	void Update () 
	{
		GameObject target = GetClosestUnit ();
		if (target == null)
		{
			lightningObject.SetOff();
			attackTarget = null;
			attack = false;
		}
		else
		{
			Debug.Log ("Target Added");
				
			lightningObject.SetOn();
			lightningObject.target = target.transform;
				
			attackTarget = target.GetComponent<cscript_unit>();
			attack = true;
				
			transform.LookAt (attackTarget.transform.position);
		}
		
		if (attack == true)
		{
			if (attackTarget != null)
				attackTarget.RemoveHelath (1);
			else
			{
				lightningObject.SetOff();
				attackTarget = null;
				attack = false;
			}
		}
		//transform.Rotate (new Vector3(0, 1, 0));
	}
Exemplo n.º 2
0
	// Update is called once per frame
	void Update () {
		if (currentHealth == 0)
		{
			KillUnit ();
		}

		CheckRightClick ();
		
		Movement ();
		
		//CheckForUnits ();
		
		if (attack == true)
		{
			if (attackTargetUnit != null)
				attackTargetUnit.RemoveHelath (1);
			else if (attackTargetBuilding != null)
				attackTargetBuilding.RemoveHelath (1);
			else if (attackTargetTurret != null)
				attackTargetTurret.RemoveHelath (1);
			else
			{
				gameObject.GetComponentInChildren<LightningBolt>().SetOff();
				attackTargetUnit = null;
				attack = false;
			}
			
			//gameObject.GetComponent<AudioSource>().enabled = true;
			
		}
		else
			gameObject.GetComponent<AudioSource>().Stop ();
		
		//Select Unit Code
		//if (renderer.isVisible && Input.GetMouseButton (0))
		if (Input.GetMouseButton (0) && GameObject.FindGameObjectWithTag("Master").GetComponent<cscript_master>().GetPlayer () == ownedPlayer.GetComponent<cscript_player>())
		{
			Vector3 camPos = Camera.main.WorldToScreenPoint (transform.position);
			camPos.y = cscript_selection_box.InvertScreenY (camPos.y);
			isSelected = cscript_selection_box.selection.Contains (camPos);
		}
		
		if (isSelected == true)
		{
			selectedLight.color = Color.blue;
		}
		else if (ownedPlayer.GetComponent<cscript_player>() != GameObject.FindGameObjectWithTag("Master").GetComponent<cscript_master>().GetPlayer())
		{
			selectedLight.color = Color.red;
		}
		else
		{
			selectedLight.color = Color.green;
		}
	}
Exemplo n.º 3
0
	void OnTriggerExit(Collider collider)
	{
		if (collider.gameObject.tag == "Unit")
		{
			if (GetOwnedPlayer() == collider.gameObject.GetComponent<cscript_unit>().GetOwnedPlayer ())
			{
				gameObject.GetComponentInChildren<LightningBolt>().SetOff();
				attackTargetUnit = null;
				attack = false;
			}
		}
	}
Exemplo n.º 4
0
	void OnTriggerEnter(Collider collider)
	{
		if (collider.gameObject.tag == "Unit")
		{
			if (GetOwnedPlayer() != collider.gameObject.GetComponent<cscript_unit>().GetOwnedPlayer ())
			{
				Debug.Log ("Unit Target Added");
				
				gameObject.GetComponentInChildren<LightningBolt>().SetOn();
				gameObject.GetComponentInChildren<LightningBolt>().target = collider.gameObject.transform;
				
				attackTargetUnit = collider.gameObject.GetComponent<cscript_unit>();
				attack = true;
			}
		}
		else if (collider.gameObject.tag == "Building")
		{
			if (GetOwnedPlayer() != collider.gameObject.GetComponent<cscript_building>().GetOwnedPlayer ().GetComponent<cscript_player>())
			{
				Debug.Log ("Building Target Added");
				
				gameObject.GetComponentInChildren<LightningBolt>().SetOn();
				gameObject.GetComponentInChildren<LightningBolt>().target = collider.gameObject.transform;
				
				attackTargetBuilding = collider.gameObject.GetComponent<cscript_building>();
				attack = true;
			}
		}
		else if (collider.gameObject.tag == "Turret")
		{
			if (GetOwnedPlayer() != collider.gameObject.GetComponentInChildren<cscript_turret>().GetOwnedPlayer().GetComponent<cscript_player>())
			{
				Debug.Log ("Turret Target Added");
				
				gameObject.GetComponentInChildren<LightningBolt>().SetOn();
				gameObject.GetComponentInChildren<LightningBolt>().target = collider.gameObject.transform;
				
				attackTargetTurret = collider.gameObject.GetComponentInChildren<cscript_turret>();
				attack = true;
			}
		}
	}