예제 #1
0
 void OnEnable()
 {
     InteractWithGameObject.RegisterListener(OnInteracting);
     PlayerAttackEvent.RegisterListener(OnUnitAttacked);
     LeftMouseSelectEvent.RegisterListener(OnLeftMouseSelected);
     RightMouseSelectEvent.RegisterListener(OnRightClick);
 }
예제 #2
0
    private void CameraOnScreenClick()
    {
        if (Input.GetMouseButtonDown(0))
        {
            currentSelectedObject = null;
            ray = cam.ScreenPointToRay(Input.mousePosition);


            if (Physics.Raycast(ray, out leftMouseHit))
            {
                //Debug.DrawRay(new Vector3(0, 1, 0), leftMouseHit.point, Color.red, duration: 10);
                currentSelectedObject = leftMouseHit.transform.gameObject;
                Debug.Log("Selected Object: " + leftMouseHit.transform.gameObject);
                LeftMouseSelectEvent leftMouseSelect = new LeftMouseSelectEvent();
                leftMouseSelect.selectedGameObject = leftMouseHit.transform.gameObject;
                leftMouseSelect.FireEvent();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out RaycastHit rightMouseHit))
            {
                RightMouseSelectEvent rightMouseClick = new RightMouseSelectEvent();
                rightMouseClick.rightClickGameObject = rightMouseHit.transform.gameObject;
                rightMouseClick.mousePosition        = rightMouseHit.point;
                rightMouseClick.clicker = currentSelectedObject;
                rightMouseClick.FireEvent();
                Debug.Log(rightMouseHit.transform.gameObject + " was right clicked");
            }
        }
    }
예제 #3
0
 void OnDisable()
 {
     UnitDeathEvent.UnregisterListener(OnEnemyUnitDeath);
     EnemyAttackEvent.UnregisterListener(OnEnemyUnitAttack);
     LeftMouseSelectEvent.UnregisterListener(OnLeftMouseSelected);
     RightMouseSelectEvent.UnregisterListener(OnRightMouseClick);
     PlayerAttackEvent.UnregisterListener(OnAttacked);
 }
예제 #4
0
    private void OnRightClick(RightMouseSelectEvent rightClick)
    {
        movePoint = Vector3.zero;
        if (objectToMove && gameObjectSelected != null)
        {
            //attack = false;
            //rdyToAttack = false;
            movePoint = Vector3.zero;
            //rayMove = true;

            // attack = true;
            movePoint = rightClick.rightClickGameObject.transform.position;
            stopDist  = 2.5f;

            Debug.Log(gameObjectSelected.name + " hit: " + rightClick.rightClickGameObject.name);

            //agent.ResetPath();
            //agent.SetDestination(movePoint);
        }
    }
예제 #5
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);
    }