/*
     * Code to make soldier have a rifle
     *              GameObject soldier = GameObject.FindWithTag("Soldier");
     *              PlayerController playerScript = soldier.GetComponent<PlayerController>();
     *              playerScript.SetArsenal("AK-74M");*/

    private void Awake()
    {
        SoldierS                   = this; //Set the Soldier Singleton
        ignoreMovement             = false;
        commenceProjectile         = false;
        animator                   = this.GetComponent <Animator>();
        timeUntilShootCommencement = timeToSwitchFromRunToShooting;
    }
Exemplo n.º 2
0
    public void handleDefense()
    {
        foreach (GameObject soldier in soldiers)
        {
            SoldierScript script = soldier.GetComponent <SoldierScript>();

            script.targetEnemy    = gameObject;
            script.targetPosition = transform.position;
        }
    }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     soldierScript = GetComponent<SoldierScript>();
     GameObject[] objs = GameObject.FindGameObjectsWithTag("Player");
     foreach (var obj in objs) {
         if (obj.name == "HDV_Human") {
             target = obj;
             break;
         }
     };
     if (target) {
         soldierScript.targetEnemy = target;
         soldierScript.targetPosition = target.transform.position;
     }
 }
Exemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     soldierScript = GetComponent <SoldierScript>();
     GameObject[] objs = GameObject.FindGameObjectsWithTag("Player");
     foreach (var obj in objs)
     {
         if (obj.name == "HDV_Human")
         {
             target = obj;
             break;
         }
     }
     ;
     if (target)
     {
         soldierScript.targetEnemy    = target;
         soldierScript.targetPosition = target.transform.position;
     }
 }
Exemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     selected      = false;
     soldierScript = GetComponent <SoldierScript>();
     townScript    = GetComponent <MapObject>().townHall.GetComponent <TownHallScript>();
 }
Exemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     selected = false;
     soldierScript = GetComponent<SoldierScript>();
     townScript = GetComponent<MapObject>().townHall.GetComponent<TownHallScript>();
 }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        //   Ray ray2 = Camera.main.ScreenPointToRay(Input.mousePosition);
        //   if (hit2 = Physics2D.Raycast(ray2.origin, new Vector2(0, 0)))
        //      Debug.Log(hit2.collider.name);

        if (Client.isStarted)
        {
            c.gameObject.SetActive(true);
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // the ray follows the mousr

        Physics.Raycast(ray, out hit, Mathf.Infinity);

        mouseCurrPoint = hit.point;


        GameObject hitObject = hit.transform.root.gameObject;

        Debug.Log(hitObject.name);

        if (hitObject.gameObject.GetComponent <unit>() != null && hitObject.gameObject.GetComponent <unit>().clientId == 0)
        {
            Cursor.SetCursor(cursorTextureonEnemy, hotSpot, cursorMode);
            Unit Enemy;
            foreach (Unit u in Client.getMyplayerHandler().EnemyUnits)
            {
                if (hitObject.gameObject == u.go)
                {
                    Enemy = u;


                    if (Input.GetMouseButton(1))
                    {
                        if (selectedObjets != null)
                        {
                            foreach (GameObject go in selectedObjets)
                            {
                                SoldierScript.attackEnemy(Enemy, go);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            Cursor.SetCursor(null, Vector2.zero, cursorMode);
        }


        if (Input.GetMouseButtonDown(0))
        {
            if (hitObject.name != "strCam")
            {
                if (!menuActive)
                {
                    TimeToDeclareDrag = limitToDeclareDrag;
                }
            }
            startDrag      = Input.mousePosition;
            mouseDownPoint = hit.point;

            clearSelection();
        }
        else if (Input.GetMouseButton(0))
        {
            if (!isDrag)
            {
                TimeToDeclareDrag -= Time.deltaTime;
                if (TimeToDeclareDrag <= 0 || isClientDragging(startDrag, Input.mousePosition))
                {
                    isDrag = true;
                }
            }
        }

        else if (Input.GetMouseButtonUp(0))
        {
            finishDragOnThisFrame = true;
            TimeToDeclareDrag     = 0;
            isDrag = false;
        }

        if (Input.GetMouseButtonDown(0))  //left buttn mouse clicked
        {
            if (!isDrag)
            {
                mouseClick = hit.point;
                SelectObject(hitObject);
            }
        }
        if (hit.collider.name == "Terrain" && !isDrag)
        {
            if (Input.GetMouseButtonUp(1))
            {
                GameObject TargetObject = Instantiate(Target, hit.point, Quaternion.identity) as GameObject; //clonoes the object and keeps on screen
                TargetObject.name = "Targetint";                                                             // the game object created is name "Targetint"
            }
        }

        if (isDrag)
        {
            BoxWidth  = Camera.main.WorldToScreenPoint(mouseDownPoint).x - Camera.main.WorldToScreenPoint(mouseCurrPoint).x;
            BoxHeight = Camera.main.WorldToScreenPoint(mouseDownPoint).y - Camera.main.WorldToScreenPoint(mouseCurrPoint).y;
            BoxLeft   = Input.mousePosition.x;
            BoxTop    = (Screen.height - Input.mousePosition.y) - BoxHeight;


            if (floatToBool(BoxWidth))
            {
                if (floatToBool(BoxHeight))
                {
                    startBox = new Vector2(Input.mousePosition.x, Input.mousePosition.y + BoxHeight);
                }
                else
                {
                    startBox = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
                }
            }
            else
            if (!floatToBool(BoxWidth))
            {
                if (floatToBool(BoxHeight))
                {
                    startBox = new Vector2(Input.mousePosition.x + BoxWidth, Input.mousePosition.y + BoxHeight);
                }
                else
                {
                    startBox = new Vector2(Input.mousePosition.x + BoxWidth, Input.mousePosition.y);
                }
            }

            endBox = new Vector2(startBox.x + Unsigned(BoxWidth),
                                 startBox.y - Unsigned(BoxHeight));
        }
    }