void OnEnable()
    {
        capCol = (CapsuleCollider2D)target;

        edgeCollider = capCol.GetComponent<EdgeCollider2D>();
        if (edgeCollider == null) {
            capCol.gameObject.AddComponent<EdgeCollider2D>();
            edgeCollider = capCol.GetComponent<EdgeCollider2D>();
        }

        edgeCollider.points = capCol.getPoints(edgeCollider.offset);
    }
    void OnEnable()
    {
        capCol = (CapsuleCollider2D)target;

        edgeCollider = capCol.GetComponent <PolygonCollider2D>();
        if (edgeCollider == null)
        {
            capCol.gameObject.AddComponent <PolygonCollider2D>();
            edgeCollider = capCol.GetComponent <PolygonCollider2D>();
        }

        edgeCollider.points = capCol.getPoints(edgeCollider.offset);
    }
Esempio n. 3
0
 void Start()
 {
     kapseli   = kapseli.GetComponent <CapsuleCollider2D>();
     tidudii   = GetComponent <AudioSource>();
     rb        = GetComponent <Rigidbody2D>();
     animaatio = GetComponent <Animator>();
     pisteet1  = GameObject.FindGameObjectWithTag("pistelasku").GetComponent <pistelasku>();
 }
Esempio n. 4
0
 private void Start()
 {
     // idk
     ToggleRunning(true);
     FinishChomp();
     _biteReport            = _chompTrigger.GetComponent <BiteReport>();
     _biteReport.BiteEvent += HandleBite;
     _chompTrigger.gameObject.SetActive(false);
 }
Esempio n. 5
0
 // Start is called before the first frame update
 void Start()
 {
     rb2d               = GetComponent <Rigidbody2D>();
     enemyAggro         = aggroCollider.GetComponent <EnemyAggro>();
     rightChecker       = sideCheckerRight.GetComponent <SideCheckerRight>();
     leftChecker        = sideCheckerLeft.GetComponent <SideCheckerLeft>();
     groundChecker      = groundCheckBox.GetComponent <GroundChecker>();
     avoidPlayerChecker = avoidPlayerCapsule.GetComponent <EnemyAvoidPlayerBlock>();
     thisEnemy          = enemy.GetComponent <Enemy>();
     enemyRange         = attackPoint.GetComponent <EnemyRangeCheck>();
 }
    void OnEnable()
    {
        capCol = (CapsuleCollider2D)target;

        polyCollider = capCol.GetComponent <PolygonCollider2D>();
        if (polyCollider == null)
        {
            polyCollider = capCol.gameObject.AddComponent <PolygonCollider2D>();
        }

        polyCollider.points = capCol.getPoints();
    }
Esempio n. 7
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        CapsuleCollider2D collider = collision.GetComponent <CapsuleCollider2D>();

        if (collider.CompareTag("PlayerBullet"))
        {
            // get bullet
            Bullet      bullet   = collider.GetComponent <Bullet>();
            Rigidbody2D bulletRB = bullet.GetComponent <Rigidbody2D>();

            // apply damage
            TakeDamage(bullet.damage);

            // apply knockback
            TakeKnockback(bullet.force, bulletRB.velocity.normalized);
        }
    }
    // Update is called once per frame
    void Update()
    {
        timeSincePlayerStart += Time.deltaTime; //Time.deltaTime de UnityEngine da el tiempo entre frames.
        //Debug.Log(timeSincePlayerStart);
        if (timeSincePlayerStart > partsSoundsTriggerDelay)
        {
            triggerDelaySurpassed = true;
        }
        //Debug.Log(grounded);
        if (grounded)
        {
            //animator.SetBool("Jumping", false);
            animator.SetBool("Falling", false);
        }
        else
        {
            animator.SetBool("Running", false);
            animator.SetBool("Falling", true);
        }
        Vector3 d = new Vector3(playerCollider.GetComponent <CapsuleCollider2D>().size.x / 2, 0, 0);

        rayCastHit2D1 = Physics2D.Raycast(transform.position + d, dir.normalized, dist, layerGround);  // Saves the collision with the ground (or the not collision).
        rayCastHit2D2 = Physics2D.Raycast(transform.position - d, dir.normalized, dist, layerGround);  // Saves the collision with the ground (or the not collision).


        //Debug.Log(rayCastHit2D.collider != null ? rayCastHit2D.collider.gameObject : null, rayCastHit2D.collider != null ? rayCastHit2D.collider.gameObject : null);
        Debug.DrawRay(transform.position, dir * dist, Color.red, 0.1f);     // Draws the Raycast in form of a red line in the "Scene" tab of the Unity Editor.

        bool temp = grounded;

        if (rayCastHit2D1.collider != null || rayCastHit2D2.collider != null)
        {
            grounded = true;
        }
        else
        {
            grounded = false;
        }
        // If the collider that the Raycast detected is null, then the statement will be false, and thus grounded too.
        // But if the Raycast hit something, it will contain a collider and the statement will be true, and grounded too.
        if (!temp && grounded && triggerDelaySurpassed)
        { //Efectos de caída sobre el suelo
            //Decidiendo posicion de spawneo de particulas:
            Vector3 posParts  = new Vector3(instance.transform.position.x + 0.2f, instance.transform.position.y - 0.6f, instance.transform.position.z);
            Vector3 posParts2 = new Vector3(instance.transform.position.x - 0.2f, instance.transform.position.y - 0.6f, instance.transform.position.z);

            fallParts.transform.position  = posParts;
            fallParts2.transform.position = posParts2;

            //Rafaga de particulas:
            fallParts.Play();
            fallParts2.Play();
            //Sonido de caer:
            fallSound.Play();
        }
        if (Input.GetButtonDown("Jump") && grounded && canMove)    // If the player hits the "Jump" Button as configured in the Project Settings > Input.
        {
            //animator.SetBool("Jumping", true);
            jump = true;        // Set true the jump bool.
            jumpSound.Play();
        }

        if (Input.GetButtonDown("Weight") && canChangeWeight && canMove)          // If the player hits the "Weight" Button as configured in the Project Settings > Input.
        {
            switch (WeightMode)
            {
            case 0:             //Light
                WeightMode = 2; // -> Heavy
                switchkeySoundLight.Play();
                animator.SetBool("Heavy", true);
                animator.SetBool("Light", false);
                break;

            case 2:             //Heavy
                WeightMode = 0; // -> Light
                switchkeySoundHeavy.Play();
                animator.SetBool("Heavy", false);
                animator.SetBool("Light", true);
                break;

            default:            //NoKey (Normal)
                WeightMode = 1; // -> Normal (Same provably)
                animator.SetBool("Heavy", false);
                animator.SetBool("Light", false);
                break;
            }

            //weightModeHeavy = !weightModeHeavy;     // Inverts the value of the Weight Mode (Light->Heavy / Heavy->Light).
            // print("Weight changed to " + WeightMode);                // Print "Weight changed" just for debugging purposes. This needs to be removed in the final game.
        }

        if (prevWeightMode != WeightMode)                   // If the Weight Mode has changed from one frame to the next, then do...
        {
            switch (WeightMode)                             // ... if we are in the Heavy mode...
            {
            case 2:
                rb2d.mass         = 3;                             // ... set the mass to 15.
                rb2d.gravityScale = (float)9;                      // How much the gravity attracts things.
                jumpHeight        = 24;
                speed             = 8;
                break;

            case 1:
                rb2d.mass         = 5;                            // ... we set the mass to 5.
                rb2d.gravityScale = (float)5;                     // This is how much the gravity attracts.
                jumpHeight        = 18;
                break;

            case 0:
                rb2d.mass         = 5;                              // ... we set the mass to 5.
                rb2d.gravityScale = (float)1.5;                     // This is how much the gravity attracts.
                jumpHeight        = 15;
                speed             = 8;
                break;
            }

            /*else                                                // But if we are in Light mode...
             * {
             *  rb2d.mass = 5;                                  // ... we set the mass to 5.
             *  rb2d.gravityScale = (float)0.7;                 // This is how much the gravity attracts.
             *  jumpHeight = 15;
             *  // And for debugging purposes me make the player narrower to see when he's in Light mode.
             *  if (facingRight)
             *  {
             *      //dani here, added these transform 1,1 commentary to test the jellybox since this size change won't happen!
             *      transform.localScale = new Vector3(1, 1, 1);
             *      //transform.localScale = new Vector3(0.5f, 0.5f, 1);
             *  }
             *  else
             *  {
             *     transform.localScale = new Vector3(-1, 1, 1);
             *     //transform.localScale = new Vector3(-0.5f, 0.5f, 1);
             *  }
             * }*/
        }
        prevWeightMode = WeightMode;                       // Update the weight mode so we can check in the next frame.
    }
Esempio n. 9
0
 private void Start()
 {
     player_rb = player.GetComponent <Rigidbody2D>();
 }