Пример #1
0
    public void ThrowBerry()
    {
        if (berryCount > 0)
        {
            Vector3 berryPos;

            if (playerObject.GetComponent <CharacterController2D>().IsFacingRight())
            {
                berryPos = new Vector3(playerObject.transform.position.x + 1, playerObject.transform.position.y - 0.9f, 0);
            }
            else
            {
                berryPos = new Vector3(playerObject.transform.position.x - 1, playerObject.transform.position.y - 0.9f, 0);
            }

            GameObject berry = Instantiate(berryPrefab, berryPos, Quaternion.identity, null);
            berry.name = "Berry";
            berryCount--;

            Collider2D[] colliders = Physics2D.OverlapCircleAll(berry.transform.position, 15, whatIsSlime);

            if (colliders.Length > 0)
            {
                SlimeAI bestOption = colliders[0].gameObject.GetComponent <SlimeAI>();

                float bestOptionDistance = Vector3.Distance(berry.transform.position, bestOption.transform.position);

                for (int i = 1; i < colliders.Length; i++)
                {
                    float distanceToSlime = Vector3.Distance(berry.transform.position, colliders[i].transform.position);

                    // If current slime is free and it's distance to berry is less than best option
                    if (distanceToSlime < bestOptionDistance)
                    {
                        bestOption         = colliders[i].gameObject.GetComponent <SlimeAI>();
                        bestOptionDistance = Vector3.Distance(berry.transform.position, bestOption.transform.position);
                    }
                }

                bestOption.CatchBerry(berry.transform);
            }
        }
    }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     ai = gameObject.GetComponentInParent <SlimeAI> ();
 }
Пример #3
0
 public Idle (SlimeAI stateMachine)
 {
     this.stateMachine = stateMachine;
 }
Пример #4
0
 public Attack (SlimeAI stateMachine)
 {
     this.stateMachine = stateMachine;
 }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     AI = GetComponentInParent <SlimeAI>();
 }