Esempio n. 1
0
 void Update()
 {
     timeSinceLastTarget += Time.deltaTime;
     //Find a target fish
     if (target == null || timeSinceLastTarget > timeBeforeChangingTarget)
     {
         if (target != null)
         {
             FishAi fishAi = target.GetComponent <FishAi>();
             if (fishAi != null)
             {
                 fishAi.targetedBy = null;
             }
         }
         target = FindClosestFish(GameObject.FindGameObjectsWithTag("Fish"));
         if (target != null)
         {
             FishAi fishAi = target.GetComponent <FishAi>();
             if (fishAi != null)
             {
                 fishAi.targetedBy = gameObject;
             }
         }
         timeSinceLastTarget = 0f;
     }
 }
Esempio n. 2
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        FishAi fishAi = collision.gameObject.GetComponent <FishAi>();

        if (collision.gameObject.tag == "Fish" && fishAi.hook != null)
        {
            fishCaught += fishAi.value;
            Destroy(collision.gameObject);
            CheckStages();
        }
    }
Esempio n. 3
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (going)
     {
         going = false;
         if (rb == null)
         {
             rb = GetComponent <Rigidbody2D>();
         }
         rb.bodyType = RigidbodyType2D.Kinematic;
     }
     if (collision.gameObject.tag == "Fish")
     {
         FishAi fishAi = collision.gameObject.GetComponent <FishAi>();
         fishAi.hook = gameObject;
     }
 }
Esempio n. 4
0
    GameObject FindClosestFish(GameObject[] fish)
    {
        GameObject result = null;
        float      distance;
        float      minimumDistance = Mathf.Infinity;

        foreach (GameObject fishInstance in fish)
        {
            if (fishInstance == null)
            {
                break;
            }
            FishCatcher fishCatcher = fishInstance.GetComponentInParent <FishCatcher>();
            if (fishCatcher != null && fishCatcher.fishCaught > 0)
            {
                if (fishCatcher.gameObject.layer == 9)
                {
                    distance = Mathf.Infinity;
                }
                else
                {
                    distance = Vector3.Distance(fishInstance.transform.position, transform.position) + 1f;
                }
            }
            else
            {
                FishAi fishAi = fishInstance.GetComponent <FishAi>();
                if (fishAi != null && fishAi.targetedBy != null)
                {
                    continue;
                }
                distance = Vector3.Distance(fishInstance.transform.position, transform.position);
            }
            if (distance < minimumDistance)
            {
                minimumDistance = distance;
                result          = fishInstance;
            }
        }
        return(result);
    }