Example #1
0
    public override void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (target.GetComponent <Unit>())
            {
                if (target.faction == Faction.Neutral)
                {
                    Debug.Log("Can't attack this target");
                }

                else if (target.faction != this.faction)
                {
                    SendMessage("StopAction"); // Interrupt any other actions
                    AttackScript.Attack(target);
                }
            }
            else if (target.GetComponent <Collectable>()) // Goldmine, wood
            {
                MoveScript.Move(target.transform.position);
            }

            else if (target.GetComponent <CollectableObject>()) // Collectable object
            {
                // Take the Object
            }
        }
        else
        {
            Orders.AddLast(new Order(OrderName.Mouse1, Vector3.zero, target));
        }
    }
Example #2
0
    public void SendAttackOrder(RTSGameObject target, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (directOrder)
            {
                Orders.Clear();
            }
            if (target.GetComponent <Unit>())
            {
                if (target.faction == Faction.Neutral)
                {
                    Debug.Log("Can't attack this target");
                }

                else if (target.faction != this.faction)
                {
                    SendMessage("StopAction"); // Interrupt any other actions
                    AttackScript.Attack(target);
                }
            }
            else if (target.GetComponent <Collectable>())
            {
            }
            else if (target.GetComponent <CollectableObject>())
            {
            }
        }
        else
        {
            Orders.AddLast(new Order(OrderName.Attack, Vector3.zero, target));
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        if (combatLock && InRange())
        {
            agent.enabled = false;
            if (attack != null && attack.Attack())
            {
                if (tag == "VjsMamma")
                {
                    Debug.Log("Attacking2");
                }
                enemy.GetComponent <BaseUnit>().TakeDamage(attack.TotalAttackDamage);
                if (enemy.GetComponent <BaseUnit>().health.IsDead())
                {
                    ExitCombatLock();
                }
            }
        }
        else if (combatLock && chase != null)
        {
            chase.ChangeTarget(enemy.transform.position);
        }

        if (health.IsDead())
        {
            Destroy(gameObject);
        }
    }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (currentBuilding != null)
        {
            Vector3 m = Input.mousePosition;
            Vector3 p = camera.ScreenToWorldPoint(m);
            currentBuilding.position = new Vector3(p.x, 0, p.z);
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            placeOn ^= true;//Switches from true to false.
            print("PLACE IS ON" + placeOn);
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            moveOn ^= true;
            print("MOVE IS ON" + moveOn);
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            selectOn ^= true;
            print("SELECT IS ON" + selectOn);
        }
        if (Input.GetButtonDown("Fire1") && placeOn == true)
        {
            currentBuildingNode          = mapmaker.NodefromWorldPosition(currentBuilding.position);
            currentBuildingNode.walkable = false;
            Instantiate(building, currentBuildingNode.nodeVector, Quaternion.identity);
        }
        else if (Input.GetButtonDown("Fire1") && moveOn == true)
        {
            currentBuildingNode = mapmaker.NodefromWorldPosition(currentBuilding.position);
            mapmaker.targetNode = currentBuildingNode;

            unitmovement.MoveTo();
        }
        else if (Input.GetButtonDown("Fire1") && selectOn == true)
        {
            Vector3 m = Input.mousePosition;
            Vector3 p = camera.ScreenToWorldPoint(m);
            currentBuilding.position = new Vector3(p.x, 0, p.z);
            currentBuildingNode      = mapmaker.NodefromWorldPosition(currentBuilding.position);
            unitmovement             = currentBuildingNode.currentObj.GetComponent <ObjectMovement>();
            //currentBuildingNode.currentObj = ;
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            if (attackScript != null)
            {
                attackScript.Attack();
            }
        }
    }
Example #5
0
    void Update()
    {
        // ...

        // 5 - Shooting
        bool shoot = Input.GetButtonDown("Fire1");

        shoot |= Input.GetButtonDown("Fire2");
        // Careful: For Mac users, ctrl + arrow is a bad idea

        if (shoot)
        {
            Debug.Log("SHOOTING POOP OOPO OPOOP");
            AttackScript weapon = GetComponent <AttackScript>();
            if (weapon != null)
            {
                // false because the player is not an enemy
                weapon.Attack(false);
            }
        }

        // ...
    }