Esempio n. 1
0
    void OnTriggerStay(Collider other)
    {
        if (wind)
        {
            Vector3 vector = Vector3.forward; // default
            switch (napravlen)
            {
            case 1:
            {
                vector = Vector3.forward;
                break;
            }

            case 2:
            {
                vector = Vector3.back;
                break;
            }

            case 3:
            {
                vector = Vector3.right;
                break;
            }

            case 4:
            {
                vector = Vector3.left;
                break;
            }
            }
            if (other.attachedRigidbody)
            {
                GameObject            player = GameObject.FindGameObjectWithTag("PlayerSkin");
                JoystickPlayerExample jpe    = player.GetComponent <JoystickPlayerExample>();
                //TODO: make a separate physics file
                if (jpe.isGrounded())
                {
                    if (jpe.isJoystickMoved())
                    {
                        other.attachedRigidbody.AddForce(vector * hoverForce);
                    }
                    else
                    {
                        other.attachedRigidbody.AddForce(vector * standForce, ForceMode.VelocityChange);
                    }
                }
            }
        }
    }
    void FixedUpdate()
    {
        jpe = GameObject.FindGameObjectWithTag("MC").GetComponent <JoystickPlayerExample>();


        if (Input.GetKeyDown(KeyCode.Space))
        {
            shootTongue();
        }

        if (shootTongueFlag == true)
        {
            tongue.position = Vector3.Lerp(tongue.position, targetTongueBody, (tongueSpeed * Time.deltaTime)); /*Slowly moving body tongue to this position*/

            tongue.transform.localScale = new Vector3(tongueWidth, Mathf.Sqrt(Mathf.Pow((tongue.position.y - MC.position.y), 2f) + Mathf.Pow((tongue.position.x - MC.position.x), 2f)) + 0.6f
                                                      , 0f); /**Scale the body of tongue follow the length of the head toungue**/


            jpe.gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeAll; /*prevent MC from changing positon when shooting tongue*/
            jpe.gameObject.GetComponent <Rigidbody2D>().mass        = 10000f;                           /*change mass to prevent MC moving when be hit by other*/
        }
        if (tongue.position == targetTongueBody)                                                        /*the tongue came the that position so set it return to frog*/
        {
            shootTongueFlag = false;
            collectTongue();
        }
        if (collectTongueFlag == true)
        {
            tongue.position = Vector3.Lerp(tongue.position, targetCollect, (tongueSpeed * Time.deltaTime));

            tongue.transform.localScale = new Vector3(tongueWidth, Mathf.Sqrt(Mathf.Pow((tongue.position.y - MC.position.y), 2f) + Mathf.Pow((tongue.position.x - MC.position.x), 2f)) + 0.6f
                                                      , 0f); /*Scale the body of tongue follow the length of the head toungue*/
        }
        if (tongue.position == targetCollect)
        {
            tongue.gameObject.SetActive(false);
            collectTongueFlag = false;
            jpe.SetMCMoving();                                                                     /*set MC can moving after doing shoot tougue*/
            jpe.gameObject.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.None; /*Allow MC to change positon after shooting tongue*/
            jpe.gameObject.GetComponent <Rigidbody2D>().mass        = 1f;
            shootFlag = true;

            tongue.position             = MC.position;
            tongue.transform.localScale = new Vector3(0.4f, 0.5f, 0f);
        }
    }
Esempio n. 3
0
        private void Start()
        {
            nameCharacter = Name.name;
            hitpoint      = Hitpoint.hitPoint;
            speedBullet   = SpeedBullet.speedBullet;
            demage        = Demage.demage;
            firingTimer   = FiringTimer.firingTimer;
            runTime       = RunTime.runTime;
            Agent.speed   = Speed.speed;
            fire          = false;
            BulletPrefab  = gameManager.bulletPrefab;
            GetComponent <MeshRenderer>().material.color = Color;
            HP.maxValue = Hitpoint.hitPoint;
            HP.value    = Hitpoint.hitPoint;

            if (Name.name == "Player")
            {
                JoystickPlayerExample joystick = this.gameObject.AddComponent <JoystickPlayerExample>();
                joystick.floatingJoystick = FindObjectOfType <FloatingJoystick>();
                joystick.rb      = this.GetComponent <Rigidbody>();
                joystick.speed   = Speed.speed;
                floatingJoystick = joystick.floatingJoystick;
            }
        }