Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     _TimeCount += Time.deltaTime;
     if (_TimeCount > 0.5f)
     {
         _TimeCount = 0;
         int ran = Random.Range(0, _PosParticle.Length);
         Instantiate(particle_cross, _PosParticle[ran].transform.position, Quaternion.identity);
     }
     _TimeAddHealth += Time.deltaTime;
     if (_TimeAddHealth > 0.2f && _Health > 0)
     {
         _TimeAddHealth = 0;
         _Health       -= 2;
         Player player = gameObject.GetComponentInParent <Player>();
         player._Health += 2;
         if (player._Health > 100)
         {
             player._Health = 100;
         }
         NumberText textHealth = player.gameObject.GetComponentInChildren <NumberText>();
         textHealth.SetNumberText(player._Health);
         GameControler gameControler = FindObjectOfType <GameControler>();
         if (_Health <= 0)
         {
             if (gameControler._GameObj.tag == "Enemy")
             {
                 gameControler.ChangeTurn();
             }
             Destroy(gameObject);
         }
     }
 }
Beispiel #2
0
    //---------------------------------------
    void Update()
    {
        if (isBallThrown && _TimeCount < 4f)
        {
            _TimeCount += Time.deltaTime;
            collier.SetActive(true);
        }
        if (_TimeCount > 4f)
        {
            _GameControler.ChangeTurn();
            Destroy(gameObject);
        }
        //==============
        if (_GameControler._CheckHit)
        {
            return;
        }
        if (_GameControler._TypeGame == 0 && _GameControler._GameState._IsEnemyStart)
        {
            return;
        }
        if ((Camera.main.ScreenToWorldPoint(Input.mousePosition).y < _GameControler.INood.transform.position.y || _UIManager._ListPopup[0].activeSelf) && !isPressed)
        {
            return;
        }

        if (isBallThrown)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            isPressed = true;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            isPressed = false;
            if (!isBallThrown)
            {
                throwBall();
            }
        }
        if (isPressed)
        {
            Player player = gameObject.GetComponentInParent <Player>();
            player.RotateRight();
            Vector3 vel = GetForceFrom(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition));//Vector vận tốc ban đầu
            PickRotate(vel);
            setTrajectoryPoints(transform.position, vel);
            //
            //Transform tf = collier.GetComponentInChildren<Transform>();
            //float angleZ = tf.eulerAngles.z;
            //angleZ = (360 - transform.eulerAngles.z) - 180;
            ////tf.eulerAngles = new Vector3(0, 0, angleZ);
            //Debug.Log("eulerAngles:" + transform.eulerAngles.z + " eulerAngles: " + angleZ);
        }
    }
Beispiel #3
0
    //---------------------------------------
    void Update()
    {
        if (isBallThrown && _TimeCount < 1f)
        {
            _TimeCount += Time.deltaTime;
            collier.SetActive(true);
            Vector3      dir       = _PosInitBullet[1].position - _PosInitBullet[0].position;
            float        rayLength = 30f;
            RaycastHit2D hit       = Physics2D.Raycast(_PosInitBullet[1].position, dir, rayLength);
            Debug.DrawLine(_PosInitBullet[1].position, (dir * rayLength) + _PosInitBullet[0].position, Color.red);
            lineRenderer.SetPosition(0, _PosInitBullet[1].position);
            lineRenderer.SetPosition(1, (dir * rayLength) + _PosInitBullet[0].position);
        }
        if (_TimeCount > 1f)
        {
            _GameControler.ChangeTurn();
            Destroy(gameObject);
        }
        if (_GameControler._CheckHit)
        {
            return;
        }
        if (_GameControler._TypeGame == 0 && _GameControler._GameState._IsEnemyStart)
        {
            return;
        }
        if ((Camera.main.ScreenToWorldPoint(Input.mousePosition).y < _GameControler.INood.transform.position.y || _UIManager._ListPopup[0].activeSelf) && !isPressed)
        {
            return;
        }

        if (isBallThrown)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            isPressed = true;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            isPressed = false;
            if (!isBallThrown)
            {
                throwBall();
            }
        }
        if (isPressed)
        {
            Vector3 vel = GetForceFrom(transform.position, Camera.main.ScreenToWorldPoint(Input.mousePosition));//Vector vận tốc ban đầu
            PickRotate(vel);
            setTrajectoryPoints(transform.position, vel);
        }
    }
Beispiel #4
0
    IEnumerator waitChangTurn()
    {
        yield return(new WaitForSeconds(1.5f));

        GameControler gameControler = FindObjectOfType <GameControler>();

        if (!gameControler._GameState._IsChangding)
        {
            gameControler.ChangeTurn();
        }
    }
    IEnumerator waitPick_Teleport_On()
    {
        yield return(new WaitForSeconds(0.6f));

        _GameControler._GameObj.transform.position = _posDes;
        _UIManager.SetImgButtonChoosePick();
        Destroy(_objTeleportOn);
        _GameControler._CheckHit = true;
        _UIManager.ResetImgPick();
        _GameControler.ChangeTurn();
        Destroy(gameObject);
    }
    private void ActiveOutMap()
    {
        GameObject other = GameObject.FindGameObjectWithTag("Map_Front");
        float      xMax  = other.transform.position.x + other.GetComponent <BoxCollider2D>().size.x *other.transform.localScale.x;
        float      xMin  = other.transform.position.x - other.GetComponent <BoxCollider2D>().size.x *other.transform.localScale.x;
        float      yMin  = other.transform.position.y - other.GetComponent <BoxCollider2D>().size.y *other.transform.localScale.y;

        if (gameObject.transform.position.x > xMax || gameObject.transform.position.x < xMin || gameObject.transform.position.y < yMin)
        {
            GameControler gameControler = FindObjectOfType <GameControler>();

            if (!gameControler._GameState._IsChangding)
            {
                gameControler.ChangeTurn();
            }

            Destroy(gameObject);
        }
    }
Beispiel #7
0
    private void CollionActive()
    {
        GameControler gameControler = FindObjectOfType <GameControler>();

        if (_Turn != 1)
        {
            gameControler.MoveCameraToObj();
        }
        if (!gameControler._GameState._IsChangding && _Turn == 1 && _BulletFinish)
        {
            gameControler.ChangeTurn();
        }
        if (_DestroyParent)
        {
            Destroy(gameObject.transform.parent.gameObject);//
        }
        else
        {
            Destroy(gameObject);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (_GameControler._GameState._IsChangding == false && _isReally == false)
     {
         _isReally = true;
         if (!_checkIssHit)
         {
             if (_GameControler._GameObj.tag == "Player")
             {
                 _GameControler._ListStatePickPlayer[6].Ammo -= 1;
             }
             else
             {
                 _GameControler._ListStatePickEnemy[6].Ammo -= 1;
             }
             _GameControler._CheckHit = true;
             _UIManager.ResetImgPick();
             GameControler gameControler = FindObjectOfType <GameControler>();
             if (gameControler._GameObj.tag == "Enemy")
             {
                 gameControler.ChangeTurn();
             }
         }
         _checkIssHit = true;
     }
     if (_isReally && _GameControler._GameState._IsChangding && _checkIssHit)
     {
         _isReally = false;
         _numTurn++;
         if (_numTurn == _NumTurn)
         {
             Player player = gameObject.GetComponentInParent <Player>();
             player._ISShield = false;
             Destroy(gameObject);
         }
     }
 }
Beispiel #9
0
 //---------------------------------------
 void Update()
 {
     //=======Di chuyển số theo gameObject
     if (isBallThrown && numText != null)
     {
         numText.transform.position = gameObject.transform.position;
         _timeCount += Time.deltaTime;
         if (_timeCount > 1)
         {
             _timeDestroy--;
             _timeCount = 0;
             NumberText lbNumText = numText.GetComponentInChildren <NumberText>();
             lbNumText.SetNumberText(_timeDestroy);
             if (_timeDestroy == 0)
             {
                 Instantiate(_Explosion, transform.position, Quaternion.identity);
                 _SoundControler.PlayExplosionSound(true);
                 //Chuyển turn============================
                 GameControler gameControler = FindObjectOfType <GameControler>();
                 if (!gameControler._GameState._IsChangding)
                 {
                     gameControler.ChangeTurn();
                 }
                 //==================
                 Destroy(numText);
                 Destroy(gameObject);
             }
         }
         return;
     }
     if (_GameControler._CheckHit)
     {
         return;
     }
     if (_GameControler._TypeGame == 0 && _GameControler._GameState._IsEnemyStart)
     {
         return;
     }
     if ((Camera.main.ScreenToWorldPoint(Input.mousePosition).y < _GameControler.INood.transform.position.y || _UIManager._ListPopup[0].activeSelf) && !isPressed)
     {
         return;
     }
     if (Input.GetMouseButtonDown(0))
     {
         _posDown  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         isPressed = true;
         if (!numText)
         {
             createText();
         }
     }
     else if (Input.GetMouseButtonUp(0))
     {
         isPressed = false;
         _posUp    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         if (!isBallThrown)
         {
             throwBall();
         }
     }
     if (isPressed)
     {
         Vector3 vel    = GetForceFrom(Camera.main.ScreenToWorldPoint(Input.mousePosition), _posDown); //Vector vận tốc ban đầu
         float   angle  = Mathf.Atan2(vel.y, vel.x) * Mathf.Rad2Deg;                                   //Góc tạo giữa vel và trục Ox
         Player  player = _GameControler._GameObj.GetComponent <Player>();
         angle += _Angle;
         if (player._Dir == Player.Dir.left)
         {
             angle = 360 - angle;
         }
         transform.eulerAngles = new Vector3(0, 0, angle);
         setTrajectoryPoints(transform.position, vel / gameObject.GetComponent <Rigidbody2D>().mass);
     }
 }
Beispiel #10
0
    void Update()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }

        Vector2 input = new Vector2(0, 0);

        if (_isCollectBullet)
        {
            input.x    = _collectVelocity.x;
            velocity.y = _collectVelocity.y;
        }
        else
        {
            if (_MovePlayer == MovePlayer.None)
            {
                _TimeBlink += Time.deltaTime;
                if (_TimeBlink > 4)
                {
                    if (gameObject.tag == "Player")
                    {
                        _anim.Play("Player_Blink");
                    }
                    else
                    {
                        _anim.Play("Enemy_Blink");
                    }
                    if (_TimeBlink > 6)
                    {
                        _TimeBlink = 0;
                    }
                }
                else if (gameObject.tag == "Player")
                {
                    _anim.Play("Player_Idle");
                }
                else
                {
                    _anim.Play("Enemy_Idle");
                }
                _Moving_Dust.SetActive(false);
            }
            if (_MovePlayer == MovePlayer.MoveLeft)
            {
                Destroy(GameObject.FindGameObjectWithTag("MyTurn"));
                if (gameObject.tag == "Player")
                {
                    _anim.Play("Player_Move");
                }
                else
                {
                    _anim.Play("Enemy_Move");
                }
                _Moving_Dust.SetActive(true);
                input.x = -1;
            }
            if (_MovePlayer == MovePlayer.MoveRigh)
            {
                Destroy(GameObject.FindGameObjectWithTag("MyTurn"));
                if (gameObject.tag == "Player")
                {
                    _anim.Play("Player_Move");
                }
                else
                {
                    _anim.Play("Enemy_Move");
                }
                _Moving_Dust.SetActive(true);
                input.x = 1;
            }
            if (_MovePlayer == MovePlayer.JumpLeft)
            {
                Destroy(GameObject.FindGameObjectWithTag("MyTurn"));
                if (gameObject.tag == "Player")
                {
                    _anim.Play("Player_Jump");
                }
                else
                {
                    _anim.Play("Enemy_Jump");
                }
                input.x = -1;
            }
            if (_MovePlayer == MovePlayer.JumpRight)
            {
                Destroy(GameObject.FindGameObjectWithTag("MyTurn"));
                if (gameObject.tag == "Player")
                {
                    _anim.Play("Player_Jump");
                }
                else
                {
                    _anim.Play("Enemy_Jump");
                }
                input.x = 1;
            }
            if (_MovePlayer == MovePlayer.JumpLeft && controller.collisions.below)
            {
                velocity.y = jumpVelocity;
            }
            if (_MovePlayer == MovePlayer.JumpRight && controller.collisions.below)
            {
                velocity.y = jumpVelocity;
            }
            if (!_IsCurrent)
            {
                input = new Vector2(0, 0);
            }
            else
            {
                //if (velocity.x != 0 || input.y != 0 || input.x != 0) Destroy(GameObject.FindGameObjectWithTag("MyTurn"));
            }
        }
        float targetVelocityX = input.x * moveSpeed;

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirborne);
        velocity.y += gravity * Time.deltaTime;
        if (_isCollectBullet)
        {
            _collectVelocity.y += gravity * Time.deltaTime;
        }
        else
        {
            if (velocity.x > 0)
            {
                gameObject.transform.localScale = new Vector3(1, 1, 1);
                GameObject obj = FinObjectChildByName(gameObject, "numbers_frame");
                if (obj != null)
                {
                    obj.transform.localScale = new Vector3(1, 1, 1);
                }
                _Dir = Dir.right;
            }
            else if (velocity.x < 0)
            {
                gameObject.transform.localScale = new Vector3(-1, 1, 1);
                GameObject obj = FinObjectChildByName(gameObject, "numbers_frame");
                if (obj != null)
                {
                    obj.transform.localScale = new Vector3(-1, 1, 1);
                }
                _Dir = Dir.left;
            }
        }

        controller.Move(velocity * Time.deltaTime);
        //===========
        if (CheckDie())
        {
            Player player = gameObject.GetComponent <Player>();
            if (player._IsCurrent)
            {
                GameControler gameCOntroler = FindObjectOfType <GameControler>();
                if (!gameCOntroler._GameState._IsChangding)
                {
                    gameCOntroler.ChangeTurn();
                }
            }
            Destroy(gameObject);
        }
    }