Exemplo n.º 1
0
 void OnEnable()
 {
     InteractWithGameObject.RegisterListener(OnInteracting);
     PlayerAttackEvent.RegisterListener(OnUnitAttacked);
     LeftMouseSelectEvent.RegisterListener(OnLeftMouseSelected);
     RightMouseSelectEvent.RegisterListener(OnRightClick);
 }
Exemplo n.º 2
0
    private void OnInteracting(InteractWithGameObject interact)
    {
        foreach (Transform enemy in transform)
        {
            if (!listOfChildren.Contains(enemy.gameObject))
            {
                listOfChildren.Add(enemy.gameObject);
            }

            if (enemy.gameObject == interact.InteractingWithThisGameObject)
            {
                //TODO: Fix:This overwrites the stats, so if 2 players attack different objects the last attacked object takes damage from both.
                stats = enemy.GetComponent <CharacterStats>();
            }
        }
    }
Exemplo n.º 3
0
    private void OnRightMouseClick(RightMouseSelectEvent rightClick)
    {
        if (!gameObjectSelected)
        {
            return;
        }
        //Debug.Log(rightClick.clicker.name);
        if (rightClick.clicker.transform.parent == null)
        {
            Debug.Log("No parent found!");
            return;
        }

        Debug.Log(transform.name + " " + rightClick.clicker.transform.parent.name);

        if ("Player1GameObject" != rightClick.clicker.transform.parent.name)
        {
            return;
        }

        attack      = false;
        rdyToAttack = false;
        movePoint   = Vector3.zero;
        rayMove     = true;


        //Debug.Log(rightClick.rightClickGameObject.name);

        if (rightClick.rightClickGameObject.transform.parent != transform.parent && rightClick.rightClickGameObject.tag != "Environment")
        {
            attackedObject = rightClick.rightClickGameObject;

            attack    = true;
            movePoint = rightClick.rightClickGameObject.transform.position;
            stopDist  = 2.5f;
            StartCoroutine("IMove");
            StartCoroutine("IHandleAttack");

            InteractWithGameObject interact = new InteractWithGameObject();
            interact.InteractingWithThisGameObject = rightClick.rightClickGameObject;
            interact.FireEvent();
        }
        else if (rightClick.rightClickGameObject.tag != "Unit")
        {
            Debug.Log("Clicked on Environment");
            movePoint     = rightClick.mousePosition;
            stopDist      = 1.1f;
            stopAttacking = true;
            StartCoroutine("IMove");// IMove(movePoint, stopDist));
        }
        else if (rightClick.rightClickGameObject.tag == "Unit")
        {
            Debug.Log("Clicked on Allied Unit");
            Vector3 lookAtVec = new Vector3(rightClick.rightClickGameObject.transform.position.x, transform.position.y, rightClick.rightClickGameObject.transform.position.z);
            transform.LookAt(lookAtVec);
            movePoint     = rightClick.rightClickGameObject.transform.position;
            stopDist      = 2.5f;
            stopAttacking = true;
            StartCoroutine("IMove");
        }
        agent.ResetPath();
        agent.SetDestination(movePoint);
    }