Example #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player") //if player collects growup

        {
            GameObject      go         = GameObject.Find("Player");
            playerCollision player_col = go.GetComponent <playerCollision>();

            float total_Children = player_col.getTotalChildren();
            total_Children += 1;      //increase its total children
            player_col.setTotalChildren(total_Children);
            Destroy(this.gameObject); //destroy collected one


            playerMovement player_mov = go.GetComponent <playerMovement>();



            //instantiate new cube
            GameObject a = Instantiate(myPrefab, new Vector3(other.transform.position.x, (other.transform.position.y + (total_Children * 1.1f)), other.transform.position.z), Quaternion.identity);
            rb = a.GetComponent <Rigidbody>();
            a.transform.parent = other.GetComponent <Rigidbody>().transform;



            //add it into the list
            player_col.growUp_list.Add(a);
        }
    }
Example #2
0
    void Start()
    {
        rigidBody        = GetComponent <Rigidbody2D>();
        animator         = GetComponent <Animator>();
        collisionManager = GetComponent <playerCollision>();

        endManager = FindObjectOfType <houseManager>();
    }
Example #3
0
    void Start()
    {
        StartCoroutine(PauseCoroutine());

        Time.timeScale = 1.0f;
        this.startPos  = this.transform.position;
        this.playerInput.update();
        this.rb2d           = this.GetComponent <Rigidbody2D>();
        this.coll2D         = this.GetComponent <Collider2D>();
        this.collisionState = new playerCollision(this.debugMode);
        this.audio          = this.GetComponent <AudioSource>();
    }
Example #4
0
    private void OnTriggerEnter(Collider other) // when player touches to yo obstacles
    {
        if (other.tag == "Player")
        {
            GameObject      go             = GameObject.Find("Player");
            playerCollision player_col     = go.GetComponent <playerCollision>();
            float           total_Children = player_col.getTotalChildren(); // check the total children of player object
            float           m;
            if (this.tag == "lastObstacle")                                 // this tag is for the last multiplication steps
            {
                Rigidbody rb = other.GetComponent <Rigidbody>();

                rb.constraints    = RigidbodyConstraints.FreezePositionX; // when player reaches the final multiplication steps, do not let him/her to move it in x axis
                rb.freezeRotation = true;                                 //also the collisions due to steps may cause rotation thats why rotation is freezed in the last steps

                m = int.Parse(this.gameObject.name);                      // take the name of the object, the names of multiplication steps are 1,2,3,4 respectively
                other.transform.position = new Vector3(other.transform.position.x, this.transform.position.y + 2, other.transform.position.z);

                if (total_Children == 0)
                {
                    FindObjectOfType <gameManager>().CompleteLevel(m);
                }



                if (m != 4)
                {
                    this.gameObject.GetComponent <Collider>().isTrigger = false;
                }

                m = 1;
            }
            else // if not multiplication steps
            {
                m = this.transform.localScale.y; // take the y scale which determines the height of the obstacle. Destroy that much cube from player
            }

            if (last && total_Children == 0)  // if last tour
            {
                FindObjectOfType <gameManager>().endGame();
            }


            Component[] k = other.transform.GetComponentsInChildren(typeof(Transform)); // get the children transforms of main player cube


            int a = k.Length;
            for (int i = 1; i < m + 1; i++) // destroy last added cubes after player collides into the obstacles
            {
                if (a - i >= 0)
                {
                    Component will_be_destroyed = k[a - i]; // go to the last added one
                    Destroy(will_be_destroyed.gameObject);  // destroy it
                }
            }



            if (total_Children - m < 0) // if total children is smaller than zero, than it means level is failed
            {
                FindObjectOfType <gameManager>().endGame();
            }
            else if (total_Children - m == 0) //when total children is equal to zero, then we also have player itself, so it did not failed yet but it is in the last collision in terms of
            {
                last = true;
            }

            player_col.setTotalChildren(total_Children - m); //set total children info
        }
    }