void commandUnitsToMove() { if (areAnyUnitSelected() == true) { Debug.Log("are any units eleceted"); if (Input.GetMouseButtonDown(1)) { Debug.Log("Mouse basıldı"); Vector3 mousePos = Input.mousePosition; Vector3 mouseInWorld = Camera.main.ScreenToWorldPoint(mousePos); mouseInWorld.z = 0; foreach (GameObject g in SelectionManager.me.getSelected()) { if (g.GetComponent <UnitMasterClass>() != null) { UnitMasterClass um = g.GetComponent <UnitMasterClass>(); Action a = g.AddComponent <Action_MoveToLocation>(); a.initialiseLocation(mouseInWorld); um.actionsQueue.Add(a); } } } } }
public override void Spawn(string unit) { if (!spawnPoint.activeSelf) { OnErrorOccured("Assign a spawn point"); //ErrorMessage.me.PassErrorMessage ("Assign a spawn point"); } else { var unitPos = new Vector3(transform.position.x, transform.position.y - 2, -1f); //spawnUnit = Instantiate ((GameObject)Resources.Load ("Prefabs/" + spawnUnit.name.Replace("(Clone)","")), unitPos, Quaternion.identity); spawnUnit = Instantiate((GameObject)Resources.Load("Prefabs/" + unit), unitPos, Quaternion.identity); spawnUnit.name = unit; var spawnPos = new Vector3(this.spawnPoint.transform.position.x, this.spawnPoint.transform.position.y, -1f); UnitMasterClass um = spawnUnit.GetComponent <UnitMasterClass> (); Action a = spawnUnit.AddComponent <Action_MoveToLocation> (); if (um.canWePerformAction(a)) { a.initaliseLocation(spawnPos); um.actionsQueue.Add(a); } else { Destroy(a); } } }