コード例 #1
0
    void Update()
    {
        timer += Time.deltaTime;
        if (timer < restTime)
        {
            return;
        }

        h = MyJoyStick.GetHorizontalAxisRaw(); //水平
        v = MyJoyStick.GetVerticalAxisRaw();   //垂直

        if (h != 0 && v != 0)
        {
            return;
        }
        //changePlayerFace();
        if (Edge_Mode)
        {
            Edge_Move(); return;
        }

        Record_last_below_box();
        if (!Can_be_controlled_check())
        {
            timer = 0; return;
        }
        if (check_velocity())
        {
            timer = 0; return;
        }                                           //player下落时无法被控制

        if (h != 0 || v != 0)
        {
            collider_self.enabled = false;
            RaycastHit hit;
            Ray        ray   = new Ray(transform.position, new Vector3(h, 0, v));
            bool       isHit = Physics.Raycast(ray, out hit, 1.1f);//检测移动时是否碰到物体
            try
            {
                if (drag())
                {
                    timer = 0; collider_self.enabled = true; return;
                }                                                               //拖拽检测
            }catch (NullReferenceException e) { }

            rigidbody_self.isKinematic = true;
            if (!isHit)
            {
                //Debug.Log("正常行走.");
                play_AudioSE(Normal_Move);
                RaycastHit player_down;
                player_down = ray_check(transform.position, new Vector3(0, -1, 0), 0.5f);
                if (player_down.transform == null)
                {
                    return;
                }
                iTween.MoveTo(gameObject, iTween.Hash("x", transform.position.x + h, "z", transform.position.z + v, "easeType", "linear", "speed", speed));
                //iTween.MoveTo(gameObject, iTween.Hash("x", h, "z", v, "easeType", "linear", "speed", speed));
            }
            else
            {   //前方有物体的情况
                if (check_player_up())
                {
                    collider_self.enabled = true; timer = 0; return;
                }                                                                          //正上方有物体时无法前进

                if (check_player_forward_up(hit))
                {   //可以爬上box的情况
                    //向上前进时保持在站立物体的中心
                    //Debug.Log("前方有且只有一个物体");
                    targetpos = new Vector3(hit.transform.position.x, hit.transform.position.y + 1, hit.transform.position.z);
                    //rigidbody.MovePosition(Vector3.Lerp(transform.position, targetpos, speed * Time.deltaTime));
                    play_AudioSE(Climbing_Move);
                    iTween.MoveTo(gameObject, iTween.Hash("x", targetpos.x, "y", targetpos.y, "z", targetpos.z, "easeType", "linear", "speed", speed));
                    //iTween.MoveBy(gameObject, iTween.Hash("amount", targetpos-transform.position, "easeType", "linear", "speed", speed, "delay", .1));
                }
                else
                {
                    Debug.Log("前方的物体上有1个或多个物体");
                }
            }
            collider_self.enabled = true;
            //Debug.Log("h=" + h + "  v=" + v);
        }

        timer = 0;

        //if (m_Camera_transform != null)
        //{
        //    m_CamForward = Vector3.Scale(m_Camera_transform.forward, new Vector3(1, 0, 1)).normalized;
        //    m_Move = m_CamForward * v + m_Camera_transform.right * h;
        //}
    }
コード例 #2
0
    bool drag()                                                                                               //拖动物体的实现
    {
        if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.JoystickButton0) || MyJoyStick.JoyStick_Drag) //Xbox360_Button_A
        {
            rigidbody_self.isKinematic = true;
            drag_h = MyJoyStick.GetHorizontalAxisRaw();
            drag_v = MyJoyStick.GetVerticalAxisRaw();
            if (drag_h != 0 && drag_v != 0)
            {
                return(true);
            }
            RaycastHit hit;
            Ray        ray   = new Ray(transform.position, new Vector3(-drag_h, 0, -drag_v));
            bool       isHit = Physics.Raycast(ray, out hit, drag_distanse);

            RaycastHit hit_down;
            hit_down = ray_check(transform.position, new Vector3(0, -1, 0), 0.5f);
            if (hit_down.transform == null)
            {
                Debug.Log("玩家下方没有box,不能执行拖动"); return(true);
            }
            switch (isHit)
            {
            case true:
                //Debug.Log("向后拖动物体");
                if (!drag_check())
                {
                    goto onlyPush;
                }
                //addHighLight(hit.rigidbody.gameObject);
                targetpos = new Vector3(transform.position.x + drag_h, transform.position.y,
                                        transform.position.z + drag_v);
                //iTween.MoveTo(gameObject, iTween.Hash("x", drag_h, "z", drag_v, "easeType", "linear", "speed", speed));
                iTween.MoveBy(gameObject, iTween.Hash("amount", targetpos - transform.position, "easeType", "linear", "speed", speed, "delay", .1));
                iTween.MoveBy(hit.transform.gameObject, iTween.Hash("x", drag_h, "z", drag_v, "easeType", "linear", "speed", speed, "delay", .2));
                Debug.Log("通知" + hit.transform.gameObject.name);
                hit.transform.gameObject.GetComponent <BoxManager>().Affected_boxes.Notify_Affectedbox(1f);
                return(true);

            case false:
                //向前推动
onlyPush:       //Debug.Log("向前推动物体");
                ray   = new Ray(transform.position, new Vector3(drag_h, 0, drag_v));
                isHit = Physics.Raycast(ray, out hit, drag_distanse);
                //通知boxManager
                if (Notify_boxManager != null)
                {
                    Notify_boxManager(this, new PlayerMoveDistance(new Vector3(drag_h, 0, drag_v), this.gameObject));
                }
                else
                {
                    Debug.Log("Notify_boxManager==null");
                }
                //addHighLight(hit.rigidbody.gameObject);
                //targetpos = new Vector3(transform.position.x + drag_h, transform.position.y,
                //    transform.position.z + drag_v);
                //rigidbody.MovePosition(Vector3.Lerp(transform.position, targetpos, smooth));

                iTween.MoveBy(hit.transform.gameObject, iTween.Hash("x", drag_h, "z", drag_v, "easeType", "linear", "speed", speed, "delay", .1));
                Debug.Log("player推动" + hit.transform.gameObject.name);
                hit.transform.gameObject.GetComponent <BoxManager>().Affected_boxes.Notify_Affectedbox(1f);
                return(true);
            }
        }

        return(false);
    }
コード例 #3
0
ファイル: OurEnemy.cs プロジェクト: Shashank001122/GameDev
    public void TakeDamage(int damageAmount)
    {
        if (GameObject.FindGameObjectWithTag("Player"))
        {
            health            -= damageAmount;
            Global.scorecount += damageAmount;

            mainweapon = GameObject.FindGameObjectWithTag("Weapon");
            if (health <= 0)
            {
                WaveSpawnnerScript = GameObject.FindGameObjectWithTag("wave").GetComponent <WaveSpawnner>();
                wavenumber         = WaveSpawnnerScript.currentWaveIndex;
                index = 0;
                if (wavenumber == 0)
                {
                    if (mainweapon.transform.name == "gun")
                    {
                        Destroy(gameObject);
                        Instantiate(soundObject, transform.position, transform.rotation);
                    }
                }
                if (wavenumber >= 1 && gameObject.transform.name != "smallDevil(Clone)")
                {
                    int randomNumber = Random.Range(0, 101);
                    if (randomNumber < pickUpChance)
                    {
                        if ((wavenumber == 1 && mainweapon.transform.name == "gun(Clone)") ||
                            (wavenumber == 1 && mainweapon.transform.name == "gun"))
                        {
                            pickups[0].transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2;
                            Instantiate(pickups[0], pickups[0].transform.position, transform.rotation);//gameObject.instantiate
                        }

                        else
                        {
                            char name = mainweapon.transform.name[7];
                            ind = System.Convert.ToInt32(name); //1 or 2

                            if (ind == 49)                      //pink rocket now, pick arrow or bow

                            {
                                if (gameObject.transform.name != "Sphere(Clone)")
                                {
                                    randomPickup = pickups[Random.Range(1, pickups.Length - 1)];

                                    randomPickup.transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2;

                                    Instantiate(randomPickup, randomPickup.transform.position, transform.rotation);
                                }
                            }
                            if (ind == 50)//arrow now, pick bow
                            {
                                randomPickup = pickups[2];
                                randomPickup.transform.position = (GameObject.FindGameObjectWithTag("Player").transform.position + this.gameObject.transform.position) / 2;
                                Instantiate(randomPickup, transform.position, transform.rotation);
                            }
                        }
                    }
                    int randHealth = Random.Range(0, 101);
                    playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent <MyJoyStick>();
                    playerHealth = playerScript.health;
                    if (randHealth < healthPickupChance)
                    {
                        if (scene.name == "SampleScene")
                        {
                            if (playerHealth < 8)
                            {
                                healthPickup.transform.position = this.gameObject.transform.position + new Vector3(6f, 1f, 0f);
                                Instantiate(healthPickup, transform.position, transform.rotation);
                            }
                        }
                        else
                        {
                            if (playerHealth < 10)
                            {
                                healthPickup.transform.position = this.gameObject.transform.position + new Vector3(6f, 1f, 0f);
                                Instantiate(healthPickup, transform.position, transform.rotation);
                            }
                        }
                    }
                    Destroy(gameObject);
                    Instantiate(soundObject, transform.position, transform.rotation);
                }
            }
        }
    }
コード例 #4
0
ファイル: healthpick.cs プロジェクト: Shashank001122/GameDev
 private void Start()
 {
     //getting playerscirpt of PLayer object using get component and then later on calling Heal method in Playermovement script.
     playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent <MyJoyStick>();
 }
コード例 #5
0
 // Start is called before the first frame update
 private void Start()
 {
     //playerScript =GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerMovement>();
     playerScript   = GameObject.FindGameObjectWithTag("Player").GetComponent <MyJoyStick>();
     targetPosition = playerScript.transform.position;
 }