外籍军团(ftp射击游戏)的细节

//改变刚体速度控制移动
            float tempy = rigidbody.velocity.y;
            Vector3 tempv = transform.forward * Input.GetAxis("Vertical") * movespeed;
            tempv += transform.right * Input.GetAxis("Horizontal") * movespeed;
            tempv.y = tempy;
            rigidbody.velocity = tempv;

使用Transform.translate()的方式总是丧心病狂的穿透mesh collider,用上述方式可以实现玩家与mesh collider的碰撞



                    //the bullet is not enough
                    if (zidan[index] <= 0)
                    {
                        return;
                    }
                    //fire cooldown
                    if (Time.time - firetime < jiange[index])
                    {
                        return;
                    }

                    if (Input.GetMouseButtonDown(0)) {
                        zidan[index]--;//bullet subs
                        GameObject huohua = Instantiate(huohuaobj) as GameObject;//copy the fire effect
                        huohua.transform.parent = shouqianghuohua.transform;
                        huohua.transform.localPosition = Vector3.zero;
                        huohua.transform.localEulerAngles = Vector3.zero;
                        huohua.transform.localScale = new Vector3(1f, 1f, 0);
                        huohua.SetActive(true);
                        Destroy(huohua, 0.5f);

                        RaycastHit hit;
                        if (Physics.Raycast(ca.transform.position, (Camera.main.ViewportToWorldPoint(miaozhun.transform.position) - shouqianghuohua.transform.position).normalized, out hit, 500/*,1<<8*/))
                        {
                            Debug.Log(hit.transform.name);
                            if (hit.transform.tag == "Enemy")
                            {
                                Debug.Log("enemybehit");
                                //GameObject.Find("Enemy").GetComponent<Enemy>().enemybehit(100);
                                
                                hit.transform.SendMessage("behit", 100);
                                firetime = Time.time;
                            }
                        }
                    }

手枪攻击



                    if (zidan[index] <= 0)
                    {
                        return;
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        zidan[index]--;
                        RaycastHit hit0;
                   
                        if (Physics.Raycast(ca.transform.position, (Camera.main.ViewportToWorldPoint(miaozhun.transform.position) - shouqianghuohua.transform.position).normalized, out hit0, 500/*,1<<8*/)) {
                            
                            arrow.SetActive(true);
                            arrow.transform.position = new Vector3(hit0.point.x,hit0.point.y+0.64f,hit0.point.z);
                            GameObject planobj = Instantiate(plane,new Vector3(0,10,0),this.transform.rotation) as GameObject;//copy the plane
                            planobj.SetActive(true);
                            planobj.transform.LookAt(hit0.point + new Vector3(0, 10, 0));
                            planeclone = planobj;//赋值给全局变量
                            StartCoroutine("MovePlane", hit0.point + new Vector3(0, 10, 0));//协同
                        }
                    }

    IEnumerator MovePlane (Vector3 target) {
        while (true) {
            planeclone.rigidbody.velocity = planeclone.transform.forward * 10;
            if (Vector3.Distance(planeclone.transform.position,target)<10) {
                //Debug.Log("kuaishengzhadan");
                GameObject rocketobj = Instantiate(Bullet,planeclone.transform.position,planeclone.transform.rotation) as GameObject;
                rocketobj.SetActive(true);
                rocketobj.transform.localScale = new Vector3(3,3,3);
            }

            yield return new WaitForSeconds(0.3f);
        }




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值