using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CrowdScript : MonoBehaviour
{

    public GameObject otherObject;
    public Rigidbody2D rb2dCrowd;
    public List<BallScript> balls;

    bool isJumping = true;

    void Start()
    {
        
        Rigidbody2D rb2dCrowd = gameObject.GetComponent<Rigidbody2D>();
        if(rb2dCrowd != null)
        {
            this.rb2dCrowd = rb2dCrowd;
        }
    }

    void Update()
    {
        if (Input.GetAxisRaw("RightJoystickY2") == -1 && !isJumping || Input.GetButton("Space") && !isJumping)
        {

            rb2dCrowd.AddForce(Vector3.up * 1.4f,ForceMode2D.Impulse);
            for (int i = 0; i < balls.Count; i++)
            {
                balls[i].TryJump(0.05f);
            }

        }
        //Goback();
    }
    void OnTriggerStay2D(Collider2D col)
    {
        if (!col.gameObject.CompareTag("Dog"))
        {
            isJumping = false;
        }
    }
    void OnTriggerExit2D(Collider2D col)
    {
        isJumping = true;
    }
    void OnTriggerEnter2D(Collider2D col)
    {
 
        if (col.gameObject.CompareTag("Dog"))
        {
            for (int i = 0; i < balls.Count; i++)
            {
                balls[i].TryJump(0.35f);
            }
        }
    }
}