コード例 #1
0
 protected void DeactivatePreviousTarget()
 {
     if (target)
     {
         target.Deactivate();
         target = null;
     }
 }
コード例 #2
0
 public virtual void ClearTarget()
 {
     if (target)
     {
         target.Deactivate();
         target = null;
     }
 }
コード例 #3
0
 private void OnTriggerExit2D(Collider2D collider)
 {
     if (target && collider.gameObject.GetInstanceID() == target.gameObject.GetInstanceID() && target_activated)
     {
         //Debug.Log("D");
         target.Deactivate();
         target = null;
     }
 }
コード例 #4
0
    private void Update()
    {
        // Don't respond to mouse over UI, gameobject refers to UI gameobject

        /*
         * if (Input.GetMouseButtonDown(0))
         * {
         *  Vector2 mouse_world = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         *  RaycastHit2D[] hits = Physics2D.RaycastAll(mouse_world, Vector2.zero, 0f);
         *  foreach(RaycastHit2D hit in hits)
         *  {
         *      Debug.Log(hit.transform.tag);
         *  }
         *  Debug.Log(EventSystem.current.IsPointerOverGameObject());
         * }
         */

        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            // Deactivate previous target
            if (target)
            {
                target.Deactivate();
                target = null;
            }

            Vector2      mouse_world = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit         = Physics2D.Raycast(mouse_world, Vector2.zero, 0f);
            if (hit)
            {
                string hit_tag = hit.transform.tag;
                foreach (string tag in tag_interactables)
                {
                    if (tag == hit_tag)
                    {
                        target           = hit.transform.gameObject.GetComponent <Behavior_Interactable>();
                        target_activated = false;
                        //Debug.Log("Target set: " + target);
                    }
                }
            }

            // Go towards clicked location even if not an interactable
            ref_ai_seeker.StartPath(transform.position, new Vector3(mouse_world.x, mouse_world.y, transform.position.z), OnPathReady);
        }
    }
コード例 #5
0
 protected void SetTarget(Behavior_Interactable new_target)
 {
     target           = new_target;
     target_activated = false;
 }