예제 #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.layer == LayerMask.NameToLayer("Octo"))
     {
         if (myTarget != null && collision.transform.GetInstanceID() == myTarget.GetInstanceID())
         {
             if (myCollider.IsTouching(collision))
             {
                 if (myTarget.gameObject.tag == "CapturedOcto")
                 {
                     //Lose
                     EventManager.Lose();
                     CanvasManager.OpenPanel(PanelEnum.LosePanel);
                 }
                 Destroy(myTarget.gameObject);
                 myTarget = null;
                 GameManager.Instance.AddSharkScore(1);
                 transform.rotation      = Quaternion.identity;
                 mySightCollider.enabled = true;
             }
         }
         //GameManager.Instance.AddSharkScore(1);
         //Destroy(collision.gameObject);
     }
 }
예제 #2
0
    //物理效果必使用fixedupdate函式,固定每次執行週期,不會因電腦效能而有差異造成不正常的顯示
    void FixedUpdate()
    {
        collision = 0;
        //初始值為0,使其為無窮迴圈效果。
        foreach (PolygonCollider2D i in other)
        {
            if (Trigger.IsTouching(i) == true)
            {
                ++collision;
            }
        }
        //物件本身有和標籤為ground物體接觸則collision +1
        if (Input.GetKey(KeyCode.Space) && collision > 0)
        {
            Gliding.velocity = new Vector2(0, JumpHeight) * Time.fixedDeltaTime;
        }
        //條件為按下空白鍵 加上物體和具有other的物件有接觸才能跳躍
        //限制物體不能在空中連續跳
        //按下空白鍵時給予向上之向量,並以每單位時間跑過禎量計算

        float distance = moveSpeed * Time.fixedDeltaTime * Input.GetAxis("Horizontal");

        //偵測到輸入平移鍵盤指令或搖桿指令,移動距離 = 速度 * 每一固定時間內跑過禎(frame)量 * 輸入鍵盤訊號(true=1 false=0)
        transform.Translate(Vector2.right * distance);
        //移動物體

        Gliding.drag = 0;
        //初始值為0,使其為無窮迴圈效果。
        if ((Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.LeftShift)) && Gliding.velocity.y < 0f)
        {
            Gliding.drag = 8; //滑翔下降阻力
        }
        //按下shift則空氣阻力變為8f(只有下降時才有,否則不叫做滑翔)
    }
예제 #3
0
 //This determines what happens when our object collides with a wall
 void OnTriggerEnter2D(Collider2D col)
 {
     switch (col.tag)
     {
     case "LevelBorder":
         if (edgeCollider.IsTouching(col))
         {
             if (wantedMoveType.Equals("WallToWallMove") || wantedMoveType.Equals("TimedMovement") || wantedMoveType.Equals("JumpingMovement"))
             {
                 if (speed > 0)
                 {
                     speed = -1f;
                 }
                 else if (speed < 0)
                 {
                     speed = 1f;
                 }
             }
             else if (wantedMoveType.Equals("FollowPlayer") || wantedMoveType.Equals("AttackPlayer"))
             {
                 rb2D.AddForce(new Vector2(0f, jumpHeight * 100f));
                 rb2D.gravityScale = 1;
             }
         }
         break;
     }
 }
예제 #4
0
 //Collisisons
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.gameObject.CompareTag("Player") && edge.IsTouching(col.collider))
     {
         enemyDie();
     }
     //For Special Movement Enemy.
     if (col.gameObject.name == "BrownGrass_special" || col.gameObject.name == "BrownGrass_special2")
     {
         enemyRigidbody.velocity = new Vector2(0f, 20f);
     }
 }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        Launch logic = GetComponent <Launch>();

        if (topTrigger.IsTouching(armCollider))
        {
            GetComponentInChildren <Tether> ().releaseTether();
            GetComponent <Launch>().dropDown();
        }
        if (bottomTrigger.IsTouching(armCollider) && logic.isAtMax)
        {
            logic.isIdle  = true;
            logic.isAtMax = false;
        }
    }
예제 #6
0
 private void Jump()
 {
     collision = 0;
     foreach (PolygonCollider2D i in GR.ground)
     {
         if (Trigger.IsTouching(i) == true)
         {
             ++collision;
         }
     }
     //物件本身有和標籤為ground物體接觸則collision +1
     if (Input.GetKey(KeyCode.Space) && collision > 0)
     {
         Rigidbody.velocity = new Vector2(0, JumpHeight) * Time.fixedDeltaTime * r;
     }
     //條件為按下空白鍵 加上物體和具有other的物件有接觸才能跳躍
     //限制物體不能在空中連續跳
     //按下空白鍵時給予向上之向量,並以每單位時間跑過禎量計算
 }
예제 #7
0
    private void DisplayMessage()
    {
        if (playerCollider.IsTouching(weaponCollider))
        {
            displayMessage = true;
            txt.SetActive(true);
        }
        else
        {
            displayMessage = false;
            txt.SetActive(false);
        }

        if (displayMessage == true)
        {
            if (bought == true)
            {
                win     = true;
                message = "Press 'E' to equip " + name;
                txt.GetComponent <UnityEngine.UI.Text>().text = message;

                winxd.gameObject.SetActive(true);
            }
            else
            {
                /*if (Global.GetMoney () >= price) {
                 *
                 *      txt.GetComponent<UnityEngine.UI.Text>().color = new Color(0.0f, 0.0f, 0.0f, 0.5f);
                 *
                 *      if (Input.GetKey (KeyCode.E)) {
                 *              bought = true;
                 *              displayMessage = false;
                 *              Global.SubtractMoney (price);
                 *      }
                 * } else {
                 *      txt.GetComponent<UnityEngine.UI.Text>().color = new Color(255.0f, 0.0f, 0.0f, 0.5f);
                 * }
                 * }
                 */
            }
        }
    }
예제 #8
0
    public void StopPendulum()

    //When you click you trigger the bool that keeps tracking the movement, and then it calculates the angle of the pendulum
    // to know if it's an attack dodge or miss.
    //We can add more attacks and dodges at different angles or even change the shape and the movement angles of the pendulum.
    {
        if (Input.GetKeyDown("mouse 0") && isMoving)
        {
            isMoving  = false;
            AttackRef = GameObject.Find("Attack/dodge");
            Attack something = AttackRef.GetComponent <Attack>();


            if (ColliderRef.IsTouching(SymbolRef))
            {
                if (something.is1Clicked == true)
                {
                    something.Attack1Success = true;
                    //Debug.Log("HIT");
                    //IsHit.text = "Attack Success";
                    hitAnim.SetTrigger("Hit");
                }
                if (something.is2Clicked == true)
                {
                    something.Attack2Success = true;
                    //Debug.Log("HIT2");
                    hitAnim.SetTrigger("Hit");
                    //IsHit.text = "Attack Success";
                }
                if (something.is1dClicked)
                {
                    something.Dodge1Success = true;
                    //IsHit.text = "Dodge Success";
                    hitAnim.SetTrigger("Hit");
                }
                if (something.is2dClicked)
                {
                    something.Dodge2Success = true;
                    hitAnim.SetTrigger("Hit");
                }
                if (something.is1hClicked)
                {
                    something.Heal1Success = true;
                    hitAnim.SetTrigger("Hit");
                }
                if (something.is2hClicked)
                {
                    something.Heal2Success = true;
                    hitAnim.SetTrigger("Hit");
                }
                if (something.is1sClicked)
                {
                    something.Speed1Success = true;
                    hitAnim.SetTrigger("Hit");
                }
                else if (something.is2sClicked)
                {
                    something.Speed2Success = true;
                    hitAnim.SetTrigger("Hit");
                }
            }
            else

            {
                missAnim.SetTrigger("Miss");
            }

            something.CompletePendulum();
        }
    }
예제 #9
0
    // Edge Collision is set to trigger and is on the bottom of the player so the edge collision will fire off the trigger events when the platform class touches it
    // Using the Stay and Exit methods, I got rid of setting the inAir bool to false when someone presses jump and then we won't need the if statement about negative velocity
    private void OnTriggerStay2D(Collider2D collision)
    {
        // Touching the ground
        if (collision != null && footTrigger.IsTouching(collision))
        {
            if (!collision.isTrigger)
            {
                inAir          = false;
                canFlipGravity = true;
                animator.SetBool("landed", true);
            }
        }

        // Head trigger is touching a something
        if (headTrigger.IsTouching(collision))
        {
            // Get collider's transform
            Transform blockTransform;
            blockTransform = collision.gameObject.GetComponent <Transform>();

            // A breakable block
            if (collision.gameObject.CompareTag("Break"))
            {
                // Individual bricks to fall
                for (int index = 0; index < 5; index++)
                {
                    gameObject.GetComponentsInChildren <ParticleSystem>()[0].Play();
                }

                collision.gameObject.SetActive(false);
            }

            // A hidden block
            // Will only appear if the player jumps to hit it
            if (collision.gameObject.CompareTag("Hidden") && gameObject.GetComponent <Rigidbody2D>().velocity.y >= -.5)
            {
                // Reveals the hidden block
                collision.gameObject.GetComponent <HiddenBlock>().RevealHiddenBlock();
            }

            // A mystery block
            if (collision.gameObject.CompareTag("Mystery"))
            {
                // Generate a random 0-2 int
                int rand;
                rand = Random.Range(0, 3);

                SpriteRenderer blockRenderer;
                blockRenderer = collision.gameObject.GetComponent <SpriteRenderer>();

                // Only fire if the block hasn't been used
                if (blockRenderer.color != Color.gray)
                {
                    if (rand == 0)
                    {
                        // Enemy pops out
                        var enemy = Instantiate(enemyPrefab, blockTransform.position + new Vector3(0, 1, 0), Quaternion.identity);
                    }
                    else if (rand == 1)
                    {
                        // Health pops out
                        Instantiate(healthDropPrefab, blockTransform.position + new Vector3(0, 1, 0), Quaternion.identity);
                    }
                    else
                    {
                        // Score increase pops out
                        UIElements.instance.UpdateScore(100);

                        // Play particle system
                        gameObject.GetComponentsInChildren <ParticleSystem>()[3].Play();
                    }

                    blockRenderer.color = Color.gray;
                }
            }
        }
    }