Beispiel #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (Floor == collision.gameObject)
        {
            BoxCollider2D thisCollider = this.gameObject.GetComponent <BoxCollider2D>();
            thisCollider.isTrigger = true;
            Destroy(this.gameObject);
        }
        foreach (GameObject player in players)
        {
            if (player == collision.gameObject)
            {
                DetectFoodType thisPlayers = collision.gameObject.GetComponent <DetectFoodType>();
                if (!thisPlayers.Stunned && !thisPlayers.GetWrongFood())
                {
                    BoxCollider2D thisCollider = this.gameObject.GetComponent <BoxCollider2D>();

                    //thisCollider.isTrigger = false;
                    Destroy(this.gameObject);
                }
                else
                {
                    Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), collision.gameObject.GetComponent <BoxCollider2D>());
                }
            }
        }
    }
    // Use this for initialization

    /* void Start () {
     *   //calls ridgid body of this compnent, ridgid body is what allows player movement.
     *   rb2d = GetComponent<Rigidbody2D>();
     *   //foods = GameObject.FindGameObjectsWithTag("food");
     *   animator = GetComponent<Animator>();
     *   spriteRenderer = GetComponent<SpriteRenderer>();
     *   Player2Detect = this.gameObject.GetComponent<DetectFoodType>();
     *
     * }*/
    private void OnEnable()
    {
        this.gameObject.transform.position = new Vector2(8.46f, -3.45f);
        //calls ridgid body of this compnent, ridgid body is what allows player movement.
        rb2d = GetComponent <Rigidbody2D>();
        //foods = GameObject.FindGameObjectsWithTag("food");
        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();
        Player2Detect  = this.gameObject.GetComponent <DetectFoodType>();
    }
    /*void Start()
     * {
     *  rb2d = GetComponent<Rigidbody2D>();
     *  Physics2D.IgnoreCollision(GetComponent<BoxCollider2D>(), player.GetComponent<BoxCollider2D>());
     *
     *  //spriteRenderer = GetComponent<SpriteRenderer>();
     *  anim = GetComponent<Animator>();
     *  spriteRender = GetComponent<SpriteRenderer>();
     *
     *  Player1Detect = this.gameObject.GetComponent<DetectFoodType>();
     *  Debug.Log(this.gameObject.name + Stunned1);
     * }*/

    private void OnEnable()
    {
        this.gameObject.transform.position = new Vector2(-8.88f, -3.45f);
        rb2d = GetComponent <Rigidbody2D>();
        Physics2D.IgnoreCollision(GetComponent <BoxCollider2D>(), player.GetComponent <BoxCollider2D>());

        //spriteRenderer = GetComponent<SpriteRenderer>();
        anim         = GetComponent <Animator>();
        spriteRender = GetComponent <SpriteRenderer>();

        Player1Detect = this.gameObject.GetComponent <DetectFoodType>();
        //Debug.Log(this.gameObject.name + Stunned1);
    }
    // Use this for initialization
    void Start()
    {
        AudioObject.clip = StartRound;
        AudioObject.Play();
        Screen.SetResolution(1920, 1080, true);
        P1ScoreCoins = new GameObject[2];
        P2ScoreCoins = new GameObject[2];
        P1Score      = 0;
        P2Score      = 0;
        Customer     = GameObject.FindGameObjectWithTag("Customer");
        Customers    = Resources.LoadAll <Sprite>("Sprites/Customers");
        SetCoinArrays();
        Set();
        Goal = GameObject.FindGameObjectWithTag("FoodGoal").GetComponent <ChooseRandomFood>();
        fa   = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <Falling>();
        GameObject Player1 = GameObject.Find("Player1");
        GameObject Player2 = GameObject.Find("Player2");

        P1    = Player1.GetComponent <Player1Move>();
        P2    = Player2.GetComponent <Player2Move>();
        DFTP1 = Player1.GetComponent <DetectFoodType>();
        DFTP2 = Player2.GetComponent <DetectFoodType>();
    }