Beispiel #1
0
        void onPowerSliderDragFinished()
        {
            //arrow.GetComponent<Arrow>().Shoot(powerSlider.value);

            Global.power = powerSlider.value;

            //提前生成落点
            ShootData shootData = new ShootData();
            int       index     = 0;
            float     pValue    = powerSlider.value;

            for (int i = 0, length = Global.dataListFromConfig.Count; i < length; i++)
            {
                if (Mathf.Abs(pValue - Global.dataListFromConfig[i].power) < 0.01f)
                {
                    shootData = Global.dataListFromConfig[i];
                    index     = i;
                    break;
                }
            }

            //hitPoint = GameObject.Instantiate(hitPointPrefab, shootData.hitPoint, Quaternion.identity) as GameObject;
            //Debug.Log(shootData.ToString());

            //计算靶子位移
            Vector3 targetEndPosition = GameObject.Find("targetRoot").GetComponent <TargetGenerator>().SetOverTarget(shootData.flyTime);

            //计算delta y
            float deltaY = shootData.hitPoint.y - targetEndPosition.y;

            //判断是否命中
            float realPower = powerSlider.value;

            if (Global.needControlResult)
            {
                realPower = findExactlyMissPower(targetEndPosition, index);

                //if (deltaY >= 0 && deltaY <= 1.2f)
                //{
                //    realPower = findExactlyMissPower_top(targetEndPosition, index);
                //    Debug.Log("可击中上半部!;;deltaY=" + deltaY + ";;powerSlider.value=" + powerSlider.value + ";;realPower=" + realPower);
                //    GameObject.Find("targetRoot").GetComponent<TargetGenerator>().HideAllCollider();
                //}
                //else if (deltaY < 0 && deltaY >= -1.2f)
                //{
                //    realPower -= 0.04f;
                //    Debug.Log("可击中下半部!;;deltaY=" + deltaY + ";;powerSlider.value=" + powerSlider.value + ";;realPower=" + realPower);
                //    GameObject.Find("targetRoot").GetComponent<TargetGenerator>().HideAllCollider();
                //}
                //else
                //{
                //    Debug.Log("deltaY=" + deltaY);
                //}
            }

            arrow.GetComponent <Arrow>().Shoot(realPower);
        }
Beispiel #2
0
        void OnCollisionEnter(Collision other)
        {
            if (other.transform.name == "Cube")
            {
                if (hasHitted)
                {
                    return;
                }
                hasHitted = true;


                if (Global.autoShoot)
                {
                    ShootData shootData = new ShootData {
                        flyTime = Global.flyTime, hitObjectName = other.gameObject.name, hitPoint = other.contacts[0].point, power = Global.power
                    };
                    Global.dataList.Add(shootData);
                    Debug.Log(shootData.ToString());
                }

                OnDestroyArrow();
            }

            if (other.transform.name == "level1" || other.transform.name == "level2" || other.transform.name == "level3")
            {
                if (hasHitted)
                {
                    return;
                }
                hasHitted = true;

                if (Global.autoShoot)
                {
                    ShootData shootData = new ShootData {
                        flyTime = Global.flyTime, hitObjectName = other.gameObject.name, hitPoint = other.contacts[0].point, power = Global.power
                    };
                    Global.dataList.Add(shootData);
                    Debug.Log(shootData.ToString());

                    OnDestroyArrow();

                    return;
                }



                arrowHead.SetActive(false);

                GameObject.Find("targetRoot").GetComponent <TargetGenerator>().OnBeHitted();

                //GetComponent<AudioSource>().PlayOneShot(targetHit);
                // set velocity to zero
                GetComponent <Rigidbody>().velocity = Vector3.zero;
                // disable the rigidbody
                GetComponent <Rigidbody>().isKinematic           = true;
                transform.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;

                //Debug.Log(gameObject.transform.position);
                //Debug.Log(other.contacts[0].point);
                Debug.Log(other.transform.name);

                hasHitted = true;
            }
        }