示例#1
0
    public List <TileBase> GetTilesContaining(Resource.ResourceType type)
    {
        var ret = new List <TileBase>();

        if (type == Resource.ResourceType.NULL)
        {
            foreach (List <Resource> resList in unclaimedResources.Values)
            {
                foreach (Resource res in resList)
                {
                    if (res.holder != null)
                    {
                        if (!ret.Contains(res.holder))
                        {
                            ret.Add(res.holder);
                        }
                    }
                }
            }
        }
        else
        {
            foreach (Resource res in unclaimedResources[type])
            {
                if (res.holder != null)
                {
                    if (!ret.Contains(res.holder))
                    {
                        ret.Add(res.holder);
                    }
                }
            }
        }
        return(ret);
    }
    public void CheckForChallenge(Resource.ResourceType type, int amount, Player player)
    {
        bool challengeMatched = false;

        foreach (Player _player in GameManager.Instance.AllPlayers)
        {
            if (_player == player)
            {
                foreach (Challenge challenge in _player.PlayerChallenges)
                {
                    if (challenge.TypeToCollect == type)
                    {
                        challenge.AmountCollectedKilledTrapped += amount;
                        challengeMatched = true;
                        break;
                    }
                }
                break; // Not sure
            }
        }
        if (challengeMatched)
        {
            UpdateShopChallenges(player);
        }
    }
示例#3
0
    public void setMyItem(Resource.ResourceType newResourceType)
    {
        myItem = newResourceType;
        switch (newResourceType)
        {
        case Resource.ResourceType.None:
            anim.SetBool("Wood", false);
            anim.SetBool("Bag", false);
            GameManager.instance.ShowBuildingDropZoneIndicator(false);
            break;

        case Resource.ResourceType.Wood:
            anim.SetBool("Wood", true);
            anim.SetBool("Bag", false);
            GameManager.instance.ShowBuildingDropZoneIndicator(true);
            break;

        case Resource.ResourceType.Stone:
            anim.SetBool("Wood", false);
            anim.SetBool("Bag", true);
            GameManager.instance.ShowBuildingDropZoneIndicator(true);
            break;

        case Resource.ResourceType.Gold:
            anim.SetBool("Wood", false);
            anim.SetBool("Bag", true);
            GameManager.instance.ShowBuildingDropZoneIndicator(true);
            break;

        default:
            break;
        }
    }
示例#4
0
文件: Player.cs 项目: jamioflan/LD41
    public void IncrementResourceCount(Resource.ResourceType type, int amount = 1)
    {
        //Debug.Log("IncrementResourceCount(" + type + ", " + amount + ")");
        switch (type)
        {
        case Resource.ResourceType.METAL:
            metal += amount;
            break;

        case Resource.ResourceType.GEMS:
            gems += amount;
            break;

        case Resource.ResourceType.MUSHROOMS:
            mushrooms += amount;
            break;

        case Resource.ResourceType.HUMAN_FOOD:
            humanFood += amount;
            break;

        case Resource.ResourceType.HUMAN_SKIN:
            humanSkins += amount;
            break;

        case Resource.ResourceType.BONES:
            dinosaurBones += amount;
            break;
        }
    }
示例#5
0
    public void SetMyItem(Resource.ResourceType itemType)
    {
        if (myItem == itemType)
        {
            return;
        }
        myItem = itemType;

        switch (itemType)
        {
        case Resource.ResourceType.Wood:
            anim.SetBool("Wood", true);
            anim.SetBool("Bag", false);
            break;

        case Resource.ResourceType.Stone:
        case Resource.ResourceType.Gold:
            anim.SetBool("Wood", false);
            anim.SetBool("Bag", true);
            break;

        case Resource.ResourceType.None:
        default:
            anim.SetBool("Wood", false);
            anim.SetBool("Bag", false);
            break;
        }
    }
示例#6
0
    public void DoTask()
    {
        Resource.ResourceType nextType = currentTask.GetNextMissing();
        if (nextType == Resource.ResourceType.NULL)
        {
            SetState(State.TRAVELLING_TO_TASK);

            //Debug.Log("Calling GetPath to travel to task");
            if (!SetPath(Path.GetPath(currentTile.GetKVPair(), currentTask.associatedTile.GetKVPair())))
            {
                AbandonTask();
            }
        }
        else
        {
            // Get the next resource
            var kvs = new List <KeyValuePair <int, int> >();
            foreach (TileBase tile in mgr.GetTilesContaining(nextType))
            {
                //Debug.Log(tile);
                kvs.Add(tile.GetKVPair());
            }
            //Debug.Log("Calling GetPath to retrieve resource for task");
            if (SetPath(Path.GetPath(currentTile.GetKVPair(), kvs)))
            {
                TileBase targetTile = mgr.GetTileBase(currentPath.endX, currentPath.endY);
                targetTile.FindResource(nextType).Claim(this);
                SetState(State.RETRIEVING_RESOURCE);
            }
            else
            {
                AbandonTask();
            }
        }
    }
    void RefreshCraftableList()
    {
        ClearCraftableListOldData();
        GameObject container = transform.Find("CraftableListPanel/Container").gameObject;

        Resource.ResourceType type = (builder.Type == Building.BuildingType.Kitchen ? Resource.ResourceType.ConsumableRecipe : (builder.Type == Building.BuildingType.Armory ? Resource.ResourceType.GadgetRecipe : Resource.ResourceType.MedicineRecipe));


        foreach (KeyValuePair <string, Resource> resourceRecipe in ItemManager.Instance.AllResources.Where(r => r.Value.type == type))
        {
            Resource resource = LoadManager.Instance.allResourceData[resourceRecipe.Key.Replace("Recipe:", "")];

            GameObject craftableItemGO = Instantiate(Resources.Load("Prefabs/UI/ImageWithAmountPrefab") as GameObject, container.transform);
            craftableItemGO.name = resourceRecipe.Key;

            Image image = craftableItemGO.GetComponent <Image>();
            image.sprite = Resources.Load <Sprite>(resource.spritePath);

            Button button = craftableItemGO.AddComponent <Button>();
            button.onClick.AddListener(() => { currentSelectedItemName = EventSystem.current.currentSelectedGameObject.name; RefreshItemInformation(); });

            Text amount = craftableItemGO.GetComponentInChildren <Text>();
            amount.text = ItemManager.Instance.GetResourceAmount(resource.Name).ToString();
        }
    }
示例#8
0
 public static GameObject getGameObjectFromFile(Resource.ResourceType resourceType)
 {
     if (resourceType == Resource.ResourceType.Coal)
     {
         return(Resources.Load <GameObject>("Coal_Resource"));
     }
     else if (resourceType == Resource.ResourceType.Iron)
     {
         return(Resources.Load <GameObject>("Iron_Resource"));
     }
     else if (resourceType == Resource.ResourceType.Copper)
     {
         return(Resources.Load <GameObject>("Copper_Resource"));
     }
     else if (resourceType == Resource.ResourceType.Gold)
     {
         return(Resources.Load <GameObject>("Gold_Resource"));
     }
     else if (resourceType == Resource.ResourceType.Tin)
     {
         return(Resources.Load <GameObject>("Tin_Resource"));
     }
     else if (resourceType == Resource.ResourceType.Silver)
     {
         return(Resources.Load <GameObject>("Silver_Resource"));
     }
     else
     {
         return(null);
     }
 }
示例#9
0
 public static Color getResourceColor(Resource.ResourceType type)
 {
     if (type == Resource.ResourceType.Coal)
     {
         return(Color.black);
     }
     else if (type == Resource.ResourceType.Copper)
     {
         return(new Color(219, 177, 1, 1));
     }
     else if (type == Resource.ResourceType.Gold)
     {
         return(Color.yellow);
     }
     else if (type == Resource.ResourceType.Iron)
     {
         return(new Color(218, 208, 178, 1));
     }
     else if (type == Resource.ResourceType.Silver)
     {
         return(new Color(208, 208, 208, 1));
     }
     else if (type == Resource.ResourceType.Tin)
     {
         return(Color.white);
     }
     else
     {
         return(Color.magenta);
     }
 }
示例#10
0
    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if (hit.gameObject.tag == "Exit")
        {
            in_house = false;
            this.transform.position = exit_light.transform.position;
        }
        if (hit.gameObject.tag == "Enter")
        {
            this.transform.position = entrance_pos.transform.position;
            in_house = true;
        }
        if (hit.gameObject.tag == "Pickup")
        {
            // destroy the capsule at the root (the Package)
            Destroy(hit.transform.root.gameObject);
            //Destroy(hit.transform.parent.gameObject);
            SpawnMgr.RemoveDropPod(hit.gameObject.transform);

            Resource.ResourceType resourceType = SpawnMgr.GetRandomResource();
            int bonus = SpawnMgr.GetRandomAmount();

            // get bonus points
            ResourceManager.AddToResource(resourceType, bonus);
        }
    }
示例#11
0
 public static float GetResourceAmount(Resource.ResourceType resourceType)
 {
     if (!resourcesInInventory.ContainsKey(resourceType))
     {
         resourcesInInventory.Add(resourceType, 0);
     }
     return(resourcesInInventory[resourceType]);
 }
示例#12
0
    public void RemoveResource(Resource.ResourceType type, float amount)
    {
        Resource value;

        if (resources.TryGetValue(type, out value))
        {
            value.RemoveFromThis(amount);
        }
    }
示例#13
0
    // can also use this for subtract
    public static void AddToResource(Resource.ResourceType resource, float val)
    {
        m_resources[resource].AddToVal(val);
        if (m_resources[resource].GetVal() > m_resources[resource].GetMaxValue())
        {
            m_resources[resource].SetVal(m_resources[resource].GetMaxValue());
        }

        UpdateBarScale(m_resources[resource]);
    }
示例#14
0
 public bool RegisterResourceLabel(TextBox textBox, Resource.ResourceType type)
 {
     if (_resourceTextBoxes.ContainsKey(type))
     {
         return(false);
     }
     this.Add(textBox);
     _resourceTextBoxes.Add(type, textBox);
     return(true);
 }
示例#15
0
 public static void AddResourceToInventory(Resource.ResourceType resourceType, float amount)
 {
     if (resourcesInInventory.ContainsKey(resourceType))
     {
         resourcesInInventory[resourceType] += amount;
     }
     else
     {
         resourcesInInventory.Add(resourceType, amount);
     }
 }
示例#16
0
 void _assignResource(int index, Resource.ResourceType type, FileStream stream, long offset)
 {
     // commented out types redirect to Resource to read and capture _rawData
     if (type == Resource.ResourceType.Anim)
     {
         _resources[index] = new Anim(stream, offset);
     }
     else if (type == Resource.ResourceType.Blas || type == Resource.ResourceType.Voic)
     {
         _resources[index] = new Blas(stream, offset);
     }
     //TODO: else if (type == Resource.ResourceType.Bmap) _resources[index] = new Bmap(stream, offset);
     //TODO: else if (type == Resource.ResourceType.Cust) _resources[index] = new Cust(stream, offset);
     else if (type == Resource.ResourceType.Delt)
     {
         _resources[index] = new Delt(stream, offset);
     }
     else if (type == Resource.ResourceType.Film)
     {
         _resources[index] = new Film(stream, offset);
     }
     else if (type == Resource.ResourceType.Font)
     {
         _resources[index] = new Font(stream, offset);
     }
     //TODO: else if (type == Resource.ResourceType.Gmid) _resources[index] = new Gmid(stream, offset);
     else if (type == Resource.ResourceType.Mask)
     {
         _resources[index] = new Mask(stream, offset);
     }
     //TODO: else if (type == Resource.ResourceType.Mtrx) _resources[index] = new Mtrx(stream, offset);
     else if (type == Resource.ResourceType.Panl)
     {
         _resources[index] = new Panl(stream, offset);
     }
     else if (type == Resource.ResourceType.Pltt)
     {
         _resources[index] = new Pltt(stream, offset);
     }
     // skip Rmap
     //TODO: else if (type == Resource.ResourceType.Ship) _resources[index] = new Ship(stream, offset);
     else if (type == Resource.ResourceType.Text)
     {
         _resources[index] = new Text(stream, offset);
     }
     else if (type == Resource.ResourceType.Xact)
     {
         _resources[index] = new Xact(stream, offset);
     }
     else
     {
         _resources[index] = new Resource(stream, offset);
     }
 }
示例#17
0
    public int GetResource(Resource.ResourceType _resourceType)
    {
        for (int i = 0; i < resourceList.Count; i++)
        {
            if (resourceList[i].GetResourceType() == _resourceType)
            {
                return(resourceList[i].GetAmount());
            }
        }

        return(0);
    }
示例#18
0
    public void GenChunk(Vector2 offset, MapController _mapController)
    {
        resourceSeed       = Random.Range(-100000, 100000);
        genResourcesSeed   = Random.Range(-100000, 100000);
        resourcesYieldSeed = Random.Range(-100000, 100000);
        noiseOffset        = offset;
        mapController      = _mapController;
        parent             = this.transform;
        seed              = mapController.seed;
        width             = mapController.chunkSize;
        height            = mapController.chunkSize;
        scale             = mapController.noiseScale;
        persistance       = mapController.persistance;
        lacunarity        = mapController.lacunarity;
        octaves           = mapController.octaves;
        float[,] noiseMap = Noise.GenerateNoiseMap(width, height, scale, octaves, persistance, lacunarity, seed, offset);
        float[,] underGroundResourcesNoiseMap      = Noise.GenerateNoiseMap(width, height, scale, octaves, persistance, lacunarity, resourceSeed, offset);
        float[,] underGroundResourcesYieldNoiseMap = Noise.GenerateNoiseMap(width, height, 7f, octaves, persistance, lacunarity, resourcesYieldSeed, offset);
        float[,] genResourcesNoiseMap = Noise.GenerateNoiseMap(width, height, 10f, octaves, persistance, lacunarity, genResourcesSeed, offset);
        tiles     = new Tile[width, height];
        resources = new Resource[width, height];
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                tiles[x, y] = new Tile(this, x, y, Util.getTileFromPerlin(noiseMap[x, y]));
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                GameObject objectPrefab = Util.getGameObjectFromFile(GetTileAt(x, y).type);
                GameObject tile_GO      = GameObject.Instantiate(objectPrefab, parent, true);
                tile_GO.name = "Tile_" + x + "_" + y;
                tile_GO.transform.position = new Vector3(x, Util.getYHeight(tiles[x, y].type), y);
                bool boolGenResource = Util.checkGenResource(x, y, genResourcesNoiseMap, tiles[x, y].type);
                if (boolGenResource == true)
                {
                    Resource.ResourceType type        = Util.getUnderGroundResource(x, y, underGroundResourcesNoiseMap);
                    GameObject            prefab      = Util.getGameObjectFromFile(type);
                    GameObject            resource_GO = GameObject.Instantiate(prefab, parent, true);
                    resource_GO.name = "Resource: " + type.ToString();
                    resource_GO.transform.position = new Vector3(x, Util.getYHeight(tiles[x, y].type), y);
                    resources[x, y] = new Resource(x, y, prefab, tiles[x, y], type, underGroundResourcesYieldNoiseMap[x, y]);
                }
                GetTileAt(x, y).Prefab = tile_GO;
            }
        }

        //Debug.Log("Chunk Created, Width: " + width + ", Height: " + height + ", Seed: " + seed);
    }
示例#19
0
 private void UpdatePlayerResources(int amount, Resource.ResourceType type)
 {
     foreach (Resource resource in Player.AllResources)
     {
         if (resource.Type == type)
         {
             resource.Amount += amount;
         }
     }
     Player.Shop.GetComponent <Shop>().UpdateShopResourcesAndItemsAmounts();
     //ChallengesManager.Instance.CheckForChallenge(type, amount, Player);
     UpdatePlayerResourcesUI();
 }
示例#20
0
 public void Mine()
 {
     if (resourcesInRange.Count > 0)
     {
         for (int i = 0; i < resourcesInRange.Count; i++)
         {
             Resource.ResourceType resourceType = resourcesInRange[i].GetResourceType();
             float amountOfResourceMined        = miningEfficiency[resourceType] * Time.deltaTime;
             Inventory.AddResourceToInventory(resourceType, amountOfResourceMined);
         }
         PowerGrid.ConsumePower(powerDraw * Time.deltaTime);
     }
 }
示例#21
0
    public void AddResource(Resource.ResourceType type, float amount)
    {
        Resource value;

        if (resources.TryGetValue(type, out value))
        {
            value.AddToThis(amount);
        }
        else
        {
            resources.Add(type, new Resource(type, amount));
        }
    }
示例#22
0
文件: Player.cs 项目: jamioflan/LD41
    public int GetValue(Resource.ResourceType type)
    {
        switch (type)
        {
        case Resource.ResourceType.METAL:
            return(metalValue);

        case Resource.ResourceType.GEMS:
            return(gemValue);

        case Resource.ResourceType.MUSHROOMS:
            return(mushroomValue);
        }
        return(0);
    }
示例#23
0
    public bool CreateResource(GameObject prefab, Resource.ResourceType t)
    {
        if (full && !EmptyCarriageWaiting())
        {
            return(false);
        }

        resource = Instantiate(prefab, this.transform);
        resource.GetComponent <Resource>().type = t;

        //Remove the Parent Scale
        this.transform.parent.GetComponent <Place>().removeScale(resource);

        resourceOnField = true;
        changeFullState();
        return(true);
    }
示例#24
0
    public static void RemoveResourceFromInventory(Resource.ResourceType resourceType, float amount)
    {
        if (!resourcesInInventory.ContainsKey(resourceType))
        {
            Debug.LogError("Inventory does not contain " + resourceType);
            return;
        }
        float amountOfResourceInInventory = resourcesInInventory[resourceType];

        amountOfResourceInInventory -= amount;
        if (amountOfResourceInInventory < 0)
        {
            amountOfResourceInInventory = 0;
            Debug.LogError("Removed more resources from inventory than was there.");
        }
        resourcesInInventory[resourceType] = amountOfResourceInInventory;
    }
示例#25
0
    public static void TriggerResourceEvent(EventType evType, Resource.ResourceType resType)
    {
        switch (evType)
        {
        case EventType.NOT_ENOUGH_RESOURCES:
            if (OnNotEnoughResources != null)
            {
                OnNotEnoughResources(resType);
            }

            break;

        default:
            //bla
            break;
        }
    }
        public static float Weight(this Resource.ResourceType self)
        {
            switch (self)
            {
            case Resource.ResourceType.Wood:
                break;

            case Resource.ResourceType.Iron:
                break;

            case Resource.ResourceType.Gold:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(self), self, null);
            }
            return(1.0f);
        }
示例#27
0
 public Resource FindResource(Resource.ResourceType type)
 {
     foreach (Resource r in clutteredResources)
     {
         if (r.type == type && !r.isClaimed)
         {
             return(r);
         }
     }
     foreach (Resource r in tidyResources)
     {
         if (r != null && r.type == type && !r.isClaimed)
         {
             return(r);
         }
     }
     return(null);
 }
    private void OnEnable()
    {
        Resource.ResourceType type = (builder.Type == Building.BuildingType.Kitchen ? Resource.ResourceType.ConsumableRecipe :
                                      (builder.Type == Building.BuildingType.Armory ? Resource.ResourceType.GadgetRecipe : Resource.ResourceType.MedicineRecipe));

        KeyValuePair <string, Resource> defaultCrafting = ItemManager.Instance.AllResources.FirstOrDefault(r => r.Value.type == type);

        if (defaultCrafting.Value != null)
        {
            currentSelectedItemName = defaultCrafting.Value.Name;
        }
        else
        {
            currentSelectedItemName = null;
        }

        RefreshCraftingPanel();
        EventManager.Instance.OnResourceChanged += OnResourceChanged;
    }
示例#29
0
    public void AddResource(Resource.ResourceType resourceType, int num)
    {
        switch (resourceType)
        {
        case Resource.ResourceType.Wood:
            WoodAmount += num;
            break;

        case Resource.ResourceType.Stone:
            StoneAmount += num;
            break;

        case Resource.ResourceType.Gold:
            GoldAmount += num;
            break;

        default:
            Debug.Log("Added strange type: " + resourceType.ToString());
            break;
        }
        UIManager.instance.UpdateResourceCount();
    }
示例#30
0
    public void FlashResourceText(Color color, Resource.ResourceType resourceType)
    {
        //Debug.Log ("FLASH");
        //woodCountText.color = Color.red;
        switch (resourceType)
        {
        case Resource.ResourceType.Wood:
            StartCoroutine(FlashCoroutine(color, 0));
            break;

        case Resource.ResourceType.Stone:
            StartCoroutine(FlashCoroutine(color, 1));
            break;

        case Resource.ResourceType.Gold:
            StartCoroutine(FlashCoroutine(color, 2));
            break;

        default:
            Debug.Log("Defaulting");
            break;
        }
    }
示例#31
0
文件: Unit.cs 项目: calvin-brizzi/ZC
	void FixedUpdate ()
	{
		if (state != State.Dead) { // Unit alive

			if (building) {


				if (currentConstruction) {
					Vector3 dist = this.transform.position - currentConstruction.transform.position;
					//print (dist.magnitude);
					if (dist.magnitude < 2) {
						currentConstruction.GetComponent<build> ().percentage += 1;
						currentConstruction.GetComponent<build> ().t = team;
					}else{
						//print ("GO");
						MoveUnit (transform.position, currentConstruction.transform.position);
					}
				}
			}

			if (Input.GetKeyDown (KeyCode.P) && !patrolPointSelection) {
				patrolPointSelection = true;
				print ("Set patrol points");
				patroling = false;
				patrolPointCount = 0;
			}

			if (TargetReached && !attacking && state!=State.Idle) {
				changeState(State.Idle);
			}
			if (state!=State.Idle && attacking && target != null) {
				transform.LookAt (target.transform);//Makes unit look at current attack target

			}

			if (health <= 0) {//Checks to see if target is dead
                changeState(State.Dead);
				audio.PlayOneShot (death);
			}

			CheckState ();//Checks the state of the target
			if(state!=State.Attacking){
				CheckForEnemies ();
			}
			int targetHealth = 0;

			//Gets the health of the target
			if (target != null) {
				if (targetType == TargetType.Unit) {
					targetHealth = target.gameObject.GetComponent<Unit> ().health;
				} else if (targetType == TargetType.Building) {
					targetHealth = target.gameObject.GetComponent<DestructableBuilding> ().health;
				}
			}
			//If target is out of range or dead remove it as target
			if (state!=State.Idle && target != null && !instructedAttack && Vector3.Distance (target.transform.position, transform.position) >= ((float)attackRange) || targetHealth <= 0) {
				target = null;
				attacking = false;
				if (state != State.Moving) {
                    changeState(State.Idle);
				}
			}

			//Gathering
			if ((MAX_LOAD == currentLoad) || (collectGoods && gathering && currentResource == null)) { // If the unit has reached its max load return to base or If the resource is destroyed and the grunt has not filled its capacity
				collectGoods = false;
				collectedAmount = currentLoad;
				currentLoad = 0;
				StartCoroutine ("FollowPath");
			}

			if (unitClass == Type.Grunt && collectGoods && MAX_LOAD > currentLoad && currentResource != null) {// While gathering goods increase current load
				currentLoad += gatherSpeed;
				Debug.Log (currentLoad);
				currentResource.GetComponent<Resource> ().ReduceAmountOfMaterial (gatherSpeed);
				collectedAmount = currentLoad;
			}

			if (Input.GetMouseButton (0)&& !EventSystem.current.IsPointerOverGameObject ()) {
				// Helps the selection of troops either multiple or single troop selection
				if (!clicked) {
					Vector3 cameraPosition = Camera.main.WorldToScreenPoint (transform.position);
					cameraPosition.y = Screen.height - cameraPosition.y;
					selected = AICamera.selectedArea.Contains (cameraPosition);
					GameObject aiCamera = GameObject.FindGameObjectWithTag ("MainCamera");

					if (renderer.isVisible && selected && !UnitMonitor.selectedUnits.Contains (this.gameObject) && UnitMonitor.LimitNotReached () && this.team == VarMan.Instance.pNum) {
						UnitMonitor.AddUnit (this.gameObject);
						wasSelected = true;
						audio.PlayOneShot (selectionConfirmation);
					} else if (!selected && wasSelected && !UnitMonitor.isShiftPressed ()) {
						//If either of the shift buttons are pushed then dont deselct it just add it
						UnitMonitor.RemoveUnit (this.gameObject);
						wasSelected = false;
						TargetReached = false;
                    }
                    else if (this.team != VarMan.Instance.pNum) {
                        Debug.Log("Not me!");
                    }
				}
				//Create the particle effect object that shows which object is selected
				if (wasSelected && glow == null) {
					glow = (GameObject)GameObject.Instantiate (glowSelection);
					glow.transform.parent = transform;
					glow.transform.localPosition = new Vector3 (0, 0, 0);
					if(transform.FindChild("Health Bar")){
						transform.FindChild("Health Bar").gameObject.renderer.enabled=true;
						transform.FindChild("Health Bar").transform.FindChild("Bar").gameObject.renderer.enabled=true;
					}
				}

				//If unselected remove it
				else if (renderer.isVisible && !wasSelected && glow != null) {
					GameObject.Destroy (glow);
					glow = null;
					if(transform.FindChild("Health Bar")){
						transform.FindChild("Health Bar").gameObject.renderer.enabled=false;
						transform.FindChild("Health Bar").transform.FindChild("Bar").gameObject.renderer.enabled=false;
					}
				}
			}
			//Makes the units setup a patrol point and patrol between two points
			if (Input.GetMouseButtonDown (1) && patrolPointSelection && wasSelected) {
				RaycastHit hit;
				Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
				if (Physics.Raycast (ray, out hit)) {
					mouseClick = hit.point;
					if (patrolPointCount == 0) {
						patrolPointCount = 0;
						patrolPoint1 = mouseClick;
						audio.PlayOneShot (moveConfirmation);
						MoveUnit (transform.position, patrolPoint1);
						patrolPointCount++;
					} else if (patrolPointCount == 1) {
						patrolPoint2 = mouseClick;
						patrolPointSelection = false;
						patroling = true;
						patrolPointCount = 0;
						audio.PlayOneShot (moveConfirmation);
					}

					if (patroling && !patrolPointSelection) {
						Patrol(patrolPoint1,patrolPoint2);
					}
				}
			} else if (Input.GetMouseButtonDown (1) && wasSelected && !patrolPointSelection) { 
				// Detects a players right click  and moves the selected troops top that position
				path = null;
				//Stops the players movement
				StopCoroutine ("FollowPath");
				RaycastHit hit;
				Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
				Debug.Log ("click");

				if (Physics.Raycast (ray, out hit)) {
					TargetReached = false;
					mouseClick = hit.point;
					notOverrideable = true;
					instructedAttack = false;
					Transform attackPoint = null;
					patroling = false;
					//If enemy unit attack
					if ((hit.collider.gameObject.tag == "Unit" || hit.collider.gameObject.tag == "Grunt") && hit.collider.gameObject.GetComponent<Unit> ().team != this.team) {
						audio.PlayOneShot (attackConfirmation);
						this.target = hit.collider.gameObject;
						targetType = TargetType.Unit;
						attacking = true;
						instructedAttack = true;
						notOverrideable = false;
						print ("Attack unit");
					}

					//If enemy building attack
					if ((hit.collider.gameObject.tag == "Building" || hit.collider.gameObject.tag == "Home Base" || hit.collider.gameObject.tag == "School") && hit.collider.gameObject.GetComponent<DestructableBuilding> ().team != this.team) {
						audio.PlayOneShot (attackConfirmation);
						this.target = hit.collider.gameObject;
						targetType = TargetType.Building;
						attacking = true;
						instructedAttack = true;
						notOverrideable = false;
						attackPoint = hit.transform.Find ("AttackPoint");
						print ("Attack Building");
					}

					//If resource and grunt start gathering

					if (hit.collider.gameObject.tag == "Scafold" && unitClass.Equals (Type.Grunt)) {
						//print ("GO BUILD");
						var buildPoint = hit.transform.FindChild ("BuildPoint");
						if (buildPoint) {
							//print ("SCAFFOLD SET");
							building = true;
							print (buildPoint.localPosition);
							MoveUnit (transform.position, buildPoint.position);
							currentConstruction = buildPoint.gameObject;
						}


					} else if (hit.collider.gameObject.tag == "Resource" && unitClass.Equals (Type.Grunt)) {
						audio.PlayOneShot (gatherConfirmation);
						currentResource = hit.transform.gameObject;

						if (resourceType != Resource.ResourceType.Nothing) {
							collectedAmount = 0;
							currentLoad = 0;
						}

						resourceType = currentResource.GetComponent<Resource> ().type;
						var gatherPoint = hit.transform.Find ("GatherPoint");
						gathering = true;
						attacking = false;

						if (gatherPoint) {
							collectGoods = false;
							returning = false;
							resourcePoint = gatherPoint.position;
							MoveUnit (transform.position, gatherPoint.position);
						}
					} else if (hit.collider.gameObject.tag == "Resource" || (hit.collider.gameObject.tag == "Home Base" && !unitClass.Equals (Type.Grunt) && hit.collider.gameObject.GetComponent<DestructableBuilding> ().team == this.team)) {
						//If not grunt just stop moving
                        changeState(State.Idle);
					} else if (hit.collider.gameObject.tag == "Home Base" && unitClass.Equals (Type.Grunt) && hit.collider.gameObject.GetComponent<DestructableBuilding> ().team == this.team) {
						//Return to homebase and deposit goods
						var returnPoint = hit.transform.Find ("ReturnPoint");
						attacking = false;

						if (unitClass.Equals (Type.Grunt)) {
							depositing = true;
							MoveUnit (transform.position, returnPoint.position);
						}
					} else {
						//Just move the unit
						if (!attacking) {
							audio.PlayOneShot (moveConfirmation);
						}
						building = false;
						gathering = false;
						returning = false;
						collectGoods = false;
						currentLoad = 0;

						if (targetType == TargetType.Building && attackPoint != null) {
							MoveUnit (transform.position, attackPoint.position);
						} else {
							MoveUnit (transform.position, mouseClick);
						}
					}
				}
			}
		} else {
			CheckState();
		}
	}